Sunday, 27 January 2019

C examples 2

#tutorial17#

// Program to find the average of n (n < 10) numbers using arrays

#include <stdio.h>
int main()
{
     int marks[10], i, n, sum = 0, average;
     printf("Enter n: ");
     scanf("%d", &n);
     for(i=0; i<n; ++i)
     {
          printf("Enter number%d: ",i+1);
          scanf("%d", &marks[i]);
          sum += marks[i];
     }
     average = sum/n;

     printf("Average = %d", average);

     return 0;
}
 
Output
Enter n: 5
Enter number1: 45
Enter number2: 35
Enter number3: 38
Enter number4: 31
Enter number5: 49
Average = 39
 
 

No comments:

Post a Comment

Note: only a member of this blog may post a comment.