Write a program in C to read 10 numbers from keyboard and find their sum and average
Answers
Answered by
3
Solution:
The given cøde is written in C.
#include <stdio.h>
int main(){
int sum=0,a,i;
float av=0.0;
printf("Enter 10 numbers.\n");
for(i=0;i<10;i++){
printf(">> ");
scanf("%d",&a);
sum+=a;
}
av=sum/10.0;
printf("Sum: %d\n",sum);
printf("Average: %f",av);
return 0;
}
Logic:
- Take the numbers as input.
- Add the numbers and store the result in a variable (sum).
- Display the value of the variable (sum).
- Calculate average by dividing it by 10.
- Display the average of the numbers.
See the attachment for output.
Attachments:
Similar questions