Question
Starter code: #include #define MY_PRINT(x,y,z) printf(running average is %d / %d = %.3f , x,y,z) double runningAverage(int, int); int main(int argc, char *argv[]) { int
Starter code:
#include
#define MY_PRINT(x,y,z) printf("running average is %d / %d = %.3f ", x,y,z)
double runningAverage(int, int);
int main(int argc, char *argv[]) {
int input; int count=0; int sum=0; double resu;
printf("enter number (-1 to quit): "); scanf("%d", &input);
while(input != -1) { sum+=input; ++count; resu = runningAverage(sum, count); MY_PRINT(sum, count, resu);
printf(" enter number (-1 to quit):"); scanf("%d", &input);
}
return 0; }
double runningAverage(int currentSum, int inputCount) { double avg = (double)currentSum/inputCount; return avg;
}
6. Problem D2 6.1 Specification Modify the above program, simplifying communications between functions. 6.2 Implementation name the program runningAveLocal2.c. define a function double runningAverage (int currentInput), which, given the current input currentInput, computes and returns the running average in double. Notice that compared against the previous program, this function takes only one argument current input and does not take current sum and input count as its arguments. In such a implementation, current sum and input count are not maintained in main Instead, main just pass currentInput to runningAverage (),assuming that runningAverage () somehow maintains the current sum and input count info. enter number (-1 to quit): 10 running average is 10/110.000 enter number (-1 to quit): 20 running average is 30 2 = 15.000 enter number (-1 to quit): 33 running average is 63 /3 -21.000 enter number (-1 to quit): 47 running average is 110 4-27.500 enter number (-1 to quit): 51 running average is 161 /5-32.200 enter number (-1 to quit): 63 running average is 224 6-37.333 enter number (-1 to quit): -1 red 309 %Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started