Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribedimage text in transcribed

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Structured Search For Big Data From Keywords To Key-objects

Authors: Mikhail Gilula

1st Edition

012804652X, 9780128046524

More Books

Students also viewed these Databases questions

Question

identify sources of secondary data across organisations;

Answered: 1 week ago