Find Sum and Average of Array Elements
In this example code, you will learn to find Sum and Average of Array Elements in C programming. Follow the following steps to complete the program:-
Step 1 Create an array list by input some numbers.
Step 2 add all the numbers in a variable.
Step 3 get average by the following formula
Average = sum of all elements / total number of elements.
Step 4 Print the Average, as result.
Program to Find Sum and Average of Array Elements in C
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | #include <stdio.h> int main() { int i, s=0,avg arr[5]; clrscr(); printf("\nEnter 5 Numbers : "); for(i=0; i<=4;i++) { scanf("%d",&arr[i]); s=s+arr[i]; } avg=s/5; printf("\nSum of 5 numbers is : %d",s); printf("\nAverage of 5 numbers is : %d",avg); getch(); return 0; } |
Output
Enter 5 Numbers : 2 5 4 7 12
Sum of 5 numbers is : 30
Average of 5 numbers is : 6
Check out our other C programming Examples