C Program to find average of the Arrays Elements

Write a C Program to find average of the Arrays Elements:

Required Knowledge:

C basics, Arrays

Program:

 1 #include<stdio.h>
 2  void main()
 3  {
 4      int n[5],i;
 5      int average,sum;
 6  
 7      for(i=0; i<=4; i++)
 8      {
 9          printf("Enter the number  %d:",i+1);
10  
11          scanf("%d",&n[i]);
12      }
13  
14      sum=n[0];
15  
16      for(i=1; i<=4; i++)
17      {
18          sum=sum+n[i];
19  
20          average=sum/n[i];
21      }
22      printf("average is:%d",average);
23  }

Output:


Comments

Popular posts from this blog

C program to calculate velocity

C program to find square root of a number

C program to find maximum between two numbers