201k views
1 vote
Write a main function that declares an array of 100 ints. Fill the array with random values between 1 and 100.Calculate the average of the values in the array. Output the average.

User Rlivsey
by
6.7k points

1 Answer

0 votes

Answer:

#include <stdio.h>

int main()

{

int avg = 0;

int sum =0;

int x=0;

/* Array- declaration – length 4*/

int num[4];

/* We are using a for loop to traverse through the array

* while storing the entered values in the array

*/

for (x=0; x<4;x++)

{

printf("Enter number %d \\", (x+1));

scanf("%d", &num[x]);

}

for (x=0; x<4;x++)

{

sum = sum+num[x];

}

avg = sum/4;

printf("Average of entered number is: %d", avg);

return 0;

}

User Catalin DICU
by
7.5k points