本关任务:编写一个程序,输入学生人数和每个人的成绩,计算平均成绩。 ######注意:当输入的学生人数小于等于0时,输出平均成绩为0分!
#include<stdio.h>
int main(void)
{
/*********Begin*********/
int n;
float c,total=0;
scanf("%d",&n);
if(n<=0) {printf("the number of students:the scores:average=0.00");}
else{
for(int i=1;i<=n;i++)
{
scanf("%f",&c);
total = total+c;
}
printf("the number of students:the scores:average=%.2f",total/n);
}
/*********End**********/
return 0;
}