- #1
ccky
- 15
- 0
a)Write a function,named getNumSum(),for accumulating(summing)float numbers;
-The function has no return value
-The function has 1 input argument named aSum:the current accumulative sum to be "updated" inside this function(Hint:use pass by reference)
-The function asks user for a float input,then updates the accumulative sum
*No code for input validation needed
My answner:
#include <stdio.h>
void getNumSum();
int main()
{
getNumSum();
return 0;
}
void getNumSum()
{
float aSum;
float *aSumAddr;
printf("type the floating point number :");
scanf(" %f", &aSum);
aSumAddr=&aSum; /*Pass to reference*/
printf("the current accumulative sum is %f",*aSumAddr);/*Use reference show the answer*/
}
I am so confused about above question.
Above the program,i want to ask which part i should modify?
Thanks!
-The function has no return value
-The function has 1 input argument named aSum:the current accumulative sum to be "updated" inside this function(Hint:use pass by reference)
-The function asks user for a float input,then updates the accumulative sum
*No code for input validation needed
My answner:
#include <stdio.h>
void getNumSum();
int main()
{
getNumSum();
return 0;
}
void getNumSum()
{
float aSum;
float *aSumAddr;
printf("type the floating point number :");
scanf(" %f", &aSum);
aSumAddr=&aSum; /*Pass to reference*/
printf("the current accumulative sum is %f",*aSumAddr);/*Use reference show the answer*/
}
I am so confused about above question.
Above the program,i want to ask which part i should modify?
Thanks!