#define N 50 /* 定义学生人数 */
#include "stdio.h"
void main()
{ int i,j=N;
float a[N],sum=0,ave=0;
printf("Please input %d numbbers:",N);
for(i=0;i
if(a[i]<0)
{j=i;
break;}
sum=sum+a[i] ;
}
printf("The average is %.2f\n",sum/j);
getch();
}
再写个简单点的:
#include "stdio.h"
void main()
{ int i=0;
float a,sum=0,ave=0;
printf("Please input numbbers:");
do
{
scanf("%f",&a);
i++;
sum=sum+a;
}
while(a>0) ;
ave=(sum-a)/(i-1);
printf("The average is %.2f\n",ave);
getch();
}
兄弟:能用C#吗?C语言都忘记完啦······