I am make a program that will calculate the average of numbers inputted into an array
also print the min and max numbers entered into the array
and then calculate the Standard deviation.
I think I have the average and the Standard deviation part working correctly but when running some final test I noticed that when entering my numbers in the array any number above 3 will not display in the Minimum number print.
So for example I could enter 11,12,13,14,15,16,17,18,19,20 and I would get 20 for the max and 3 for the min.
Any idea on why I am getting this. I am guessing something is limiting that variable but I can't see what.
Sorry if this is a stupid question.
Thanks,
#include <stdio.h>
#include <math.h>
int main(void)
{
//variables
float num[100];
float average=0;
float var=0;
float stand=0;
float sum=0;
float sum1=0;
int i=0;
int n=10;
int min;
int max;
//ask user to enter numbers
printf("Enter 10 numbers\n",n);
for(i=0; i<n; i++)
{
scanf("%f", &num[i]);
}
//find average of numbers
for(i=0; i<n; i++)
{
sum = sum + num[i];
}
average = sum /(float) n;
for(i=0; i<n; i++)
{
//if greater than max
if(num[i]>max)
{
max = num[i];
}
}
//if smaller than min
if(num[i]<min)
{
min = num[i];
}
//calculate standard deviation
for(i=0; i<n; i++)
{
sum1 = sum1 + pow((num[i] - average),2);
}
stand = sqrt(sum1/n);
//print results
printf("Average of all numbers = %.2f\n", average);
printf("Maximum number = %d\n", max);
printf("Minimum number = %d\n", min);
printf("Standard deviation = %.2f\n", stand);
system("PAUSE");
return 1;
}