Sum And Average Of Array Element - C Program

Sum And Average Of Array Element

#include <stdio.h>
int main()
{
	int num[10];
	int sum=0,i;
	float avg;
	
	printf("Enter 10 numbers\n");
	for(i=0;i<10;i++) 
        scanf("%d",&num[i]);
    printf("Array Elements...\n");
    for(i=0;i<10;i++)
		printf("%d ",num[i]);

	for(i=0;i<10;i++)
		sum=sum+num[i];
	avg=sum/10.0;
	printf("\nSum :%d\nAverage :%f",sum,avg);
    return 0;
}

Output - Sum And Average Of Array Element

Enter 10 numbers 
10                                                                                                     
20                                                                                                                      
30                                                                                                                      
40                                                                                                                      
50                                                                                                                      
60                                                                                                                      
15                                                                                                                      
25                                                                                                                      
34                                                                                                                      
56                                                                                                                      
Array Elements...                                                                                                       
10 20 30 40 50 60 15 25 34 56                                                                                           
Sum :340                                                                                                                
Average :34.000000   
Compile and Run Online