还有这个程序,帮忙看下,total/n,这2个值都是int型的,算出来的average好像也是int型的?该怎么改呢?还是我想错了?
#include<stdio.h>
#include<conio.h>
float main()
{
int n,i,max,min,total=0,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=max>a[i]?max:a[i];
min=min<a[i]?min:a[i];
}
}
average=total/n;
printf("\nthe max is %d\nthe min is %d\nthe average is %.2f\nthe total is d",max,min,average,total);
getch();
return 0 ;
}