
User will enter a bunch of number and it's going to find the average of those numbers.
Before we create an array with for example 10 numbers but here the user can decide how many the user can enter.
#include <stdio.h>
int main()
{
int i, howMany = 0;
int total= 0;
float average = 0.0;
int* pointsArray = 0;
printf("How many numbers do you want to average?\n");
scanf(" %d", &howMany);
pointsArray = (int *) malloc(howMany * sizeof(int)); (create an array based on used on user's input)
printf("Enter them hoss! \n");
for(i=0; i<howMany; i++){
scanf(" %d", &pointsArray[i]);
total += pointsArray[i]; (to calculate total)
}
average = (float)total/(float)howMany;
printf("Average is %f", average);
return 0;
}
Comments
Post a Comment