C program to find average of N numbers using an array: To find an average of total numbers in the array.

What is average?
The mean is the average. When you add all the numbers and divide sum by a number of total numbers the resultant value is referred to as average.

Average formula
The average = sum of all numbers / total numbers

Algorithm to find average of N number

  1. Declare variables. N, Sum, array[], avg
  2. Take Total number. N
  3. Take N input
    For i=1 to N
    Input array1[i]
    Add array numbers. Sum=Sum+array[i]
  4. Calculate average. avg=Sum/N
  5. Print Average of numbers

C program to find average of N numbers using array

#include<stdio.h>
main()
{
int i,j,sum=0,num;
float avg;
printf("Enter number\n");
scanf("%d",&num);
int array[num];
printf("Enter %d numbers\n",num);
for(i=0;i<num;i++)
{
scanf("%d",&array[i]);
sum+=array[i];
}
avg=(float)sum/num;
printf("Average of %d numbers is %f\n",num,avg);
}

Output:

C program to find average of N numbers

Write A Comment