Hi guys, I'm new on here and iv searched through the forum for something to fix my problem but alas i havnt found anything!I am trying to write a program using arrays and loops to determine the average of a set of numbers and then comparing each individual value of the array to the average to see which is greater. I have attached comments to say what happens when it compiles.
Code:
#include <stdio.h>
int main ()
{
int i, array[10]={0,1,2,3,4,5,6,7,8,9,};
i= 0;
float average,sum;
average=sum=0.0;
while(i<10)
{
sum=sum+array[i];
i++;
}
average=sum/i;
printf("The average is %f\n", average);
i=0;
while (i<10)
{
if (array[i]> average){
printf("%d\n is greater than average %f", array[i],average);
i++;
}
if (array[i]< average){
printf("%d\n is less than average %f", array[i],average);
i++;
} /*when compiled i get (a blank space) is less than the average 4.5 and so on */
}
return 0;
}