write a program to read 10 numbers from the keyboard and find their sum and average
Answers
#include <stdio.h>
void main()
{
int i,n,sum=0;
float avg;
printf("Input the 10 numbers : \n");
for (i=1;i<=10;i++)
{
printf("Number-%d :",i);
scanf("%d",&n);
sum +=n;
}
avg=sum/10.0;
printf("The sum of 10 no is : %d\nThe Average is : %f\n",sum,avg);
}
hope it is useful for u
Below are the program for the above problem in C language is listed below:
Explanation:
#include <stdio.h>// header file inclusion.
int main() // main function.
{
int i=0, sum=0,number; // variable declaration which store integer value.
float avg=0; // variable declaration for decimal value.
while(i<10) // while loop which executes its body on 10 times.
{
scanf("%d",&number); // input statement to take the input.
sum=sum+number; // add the every input number.
i++; // increment for while loop.
}
avg=sum/10; // count the average of inputted value.
printf("Sum=%d Avg=%f",sum,avg); // print the sum and average value.
return 0; // return the statement.
}
Output:
- If the user enters 1,2,3,4,5,6,7,8,9,10 then the output is "Sum=55 Avg=5.000000"
Code explanation:
- Here in this program, there is a while loop which executes his body for the 10 times to take the 10 value from the user
- The value is get added to the Sum variable every time.
- Then the average is calculated by the help of Sum divided by 10.
- Then the average and sum is displayed by the help of prinf function
Learn More:
- C-Language : https://brainly.in/question/610076