Skip to main content

C program to find the average of user input using array

This program accepts users to input up to any number and stores it Array. Then calculate the average of stored numbers by calculating the total or sum and then dividing it by a number of inputs.

This C program uses an array to store scores or numbers in a declared array.

In for loop program ask the user to input numbers and store them in the array.

Once the loop is over code calculate the average.

//average of user input numbers or scores using array
#include <stdio.h>
int main() {
int arrayVal[100],cntScore,Total=0,i; 
float average;
printf("Enter No of Scores to Calculate Average\t");
scanf("%d",&cntScore);
for(i=0;i<cntScore;i++)
{
    printf("Enter %d Score",i+1);
    scanf("%d",&arrayVal[i]);
    Total = Total + arrayVal[i];
}
average = (float)Total/cntScore;
printf("Average of %d Score is %.2f",cntScore,average);
return 0;
}

Output

Enter No of Scores to Calculate Average	3
Enter 1 Score	11
Enter 2 Score	22
Enter 3 Score	33
Average of 3 Score is 22.00

Code is available to download from GitHub

https://github.com/malpuresuhas/Github_C_Program/blob/master/averageNumbers.c

Leave a Reply

Your email address will not be published. Required fields are marked *