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
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