Hello. Im having trouble calculating the average of an array. Ill get right to it and post my code.
Code:
int main(void)
{
float *list,average = 0, sum = 0;
int sortnum, j, arrayinput;
printf("Enter the number of data points to average: ");
scanf("%d",&sortnum);
list = malloc(sortnum * sizeof(int));
for (j = 0; j < sortnum; j++)
scanf("%f", list + j);
printf("You entered the following:\n");
for (j = 0; j < sortnum; j++)
printf("%f\n", *(list + j));
free(list);
sum = *list + sortnum;
average = sum/sortnum;
printf("Average %d", average);
return 0;
}
When I run the program everything works fine, except the average is always 0. Any help will be appreciated.
Thanks