Question: Write in c language and save in a .c file Part 1 Write a function called compute_average that: *reads from the terminal a series of

Write in c language and save in a .c file

Part 1

Write a function called compute_average that:

*reads from the terminal a series of positive double numbers until the user enters a negative number

*for each iteration computes and displays the average of all the numbers already entered

*returns the average of all numbers entered.

For example, if the user enters 10 0 23 -4, the function should return 11. The negative number acting as a sentinel should not be included in calculations or the output. Write the function interface comment, with proper precondition and postcondition.

Part 2 This part is similar to a).

Write a function called compute_moving_average that:

*reads from the terminal a series of positive double numbers until the user enters a negative number

*for each iteration computes and displays the average of the most recent 3 numbers already entered(this is called a moving average with a windows size of 3)

*returns the last moving average computed after the user enters a negative number.

The negative number acting as a sentinel should not be included in calculations or the output. Hint: one could use three variables to store the most recent three numbers entered. At each iteration the variables could be updated accordingly. Write the function interface comment, with proper precondition and postcondition.

Part 3 Write a main function that demonstrates the functions from parts a) and b).

Test your program thoroughly so that all conditional branches are checked. Include a screenshot in the PDF file with the program output in the terminal.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Part 1 Function computeaverage Lets start by writing the C function computeaverage which reads a series of positive double numbers from the terminal c... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!