Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Complete the program, sum.c, by translating the algorithm given there into C. Th

ID: 3872119 • Letter: C

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

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:

Explanation / Answer

#include <stdio.h>

int main()
{
int sum = 0, n;
int count = 0;
double average;
printf("Enter an integer value(0 to quit): ");
scanf("%d", &n);
while(n != 0) {
sum+=n;
count++;
printf("Enter an integer value(0 to quit): ");
scanf("%d", &n);
}
average = sum/(double)count;
printf("The average of %d input values is %lf", count, average);
  
return 0;
}

Output:

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote