How does a C program to store numbers and calculate average using arrays work?

 Courtesy: Programiz.com


Here, the user is first asked to enter the number of elements. This number is assigned to n.

If the user entered integer is greater less than 1 or greater than 100, the user is asked to enter the number again. This is done using a while loop.

Then, we have iterated a for loop from i = 0 to i . In each iteration of the loop, the user is asked to enter numbers to calculate the average. These numbers are stored in the num[] array.

scanf("%f", &num[i]);

And, the sum of each entered element is computed.

sum += num[i];

Once the for loop is completed, the average is calculated and printed on the screen.

Comments

Popular posts from this blog

C program to read and display book information using structure

Count positive, negative and zero values in an array

Maximum value from array