Write ONE program to complete TWO task: 1) calculate the average value of q wher
ID: 3543661 • Letter: W
Question
Write ONE program to complete TWO task: 1) calculate the average value of q where q=100+200+300+...700+800+900+...M and 2) print the average value of q on the screen.
The program should include ONE sub-function named compute and ONE main function. Sub-function compute completes ONE task:
a) Must use a loop to generate
q=100+200+300+...700+800+900+...M (Where M is an integer. Then calculate the average value of q;
A main function should complete TWO task:
a)read the input M from keyboard and pass it to the funtion compute;
b)print the average value of q on the screen
Explanation / Answer
#include<stdio.h>
int compute(int M)
{
int i=100;
int count =0;
int sum = 0;
for(i=100; i<=M; i=i+100)
{
sum = sum + i;
count++;
}
return sum/count;
}
int main()
{
int M;
printf("Enter the value of M :");
scanf("%d",&M);
printf("Average value Given by %d ",compute(M));
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.