Question
Complete the program, sum.c, by translating the algorithm given there into C. This program sums the numbers given to it as input. You should terminate
Complete the program, sum.c, by translating the algorithm given there into C. This program sums the numbers given to it as input. You should terminate the input with the end-of-file character.
int main()
{
/* Initialize the sum */
/* Get the first input */
/* While there is more input */
/* Accumulate the sum */
/* Get the next input */
/* Print the results */
}
Copy your sum.c file into a new file, avg.c. Modify the algorithm and then the code to print the average of the input instead of the sum. Here's an example run:
Enter an integer value: 10 Enter an integer value: 20 Enter an integer value: 30 Enter an integer value: [control-D] The average of 3 input values is 20.000000
A more interesting type of average is a weighted average. A weighted average is computed by summing up a series of weight/value pairs, and then dividing the result by the sum of the weights. Copy the avg.c program into weight.c and modify it to read and compute a weighted average. Here's an example run:
Enter a weight/value pair: 20 90 Enter a weight/value pair: 30 80 Enter a weight/value pair: 50 60 Enter a weight/value pair: [control-D] The weighted average of 3 input values is 72.0
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