[求助]程序错在哪?????
求各位大虾,小弟的程序错在哪里,感谢了。。。
/*随意输入N个数,求最大值,最小值,和平均值。*/
#include<stdio.h>
void main()
{
int n,i,max,min,total,a[50];
float average;
printf("how many numbers do you want to deal with?(n<=50) ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("the %dth number is : ",i+1);
scanf("%d",&a[i]);
total+=a[i];
if(i==0)
{
max=a[i];
min=a[i];
}
else
{
max=a[i]>a[i-1]?a[i]:a[i-1];
min=a[i]<a[i-1]?a[i]:a[i-1];
}
}
average=total/n;
printf("\nthe max is %d\nthe min is %d\nthe average is %.2f",max,min,average);
}