I've been looking for a solution quite a while now, but did not manage to find anything.
I need a program which takes the users input (a random amount of integers) until EOF, sums them up and gives me back the average.
I tried it using an array but I am not sure whats my mistake here. I managed to get it working with a fixed size array. But I need a flexible one.. Is this even possible?
Here is what I got so far:
#include <stdio.h>
int main()
{
int count = 3;
int numbers[count];
long sum;
float average;
int i;
for (i = 0; i < count; i++) {
while (scanf("%d", &numbers[i]) != EOF) {
sum += numbers[i];
}
}
average = (float)sum/count;
printf("Average of your numbers is: %.2f\n",average);
return 0;
}