C语言-5-循环问题

C语言-5-循环问题

问题描述:

img


本关任务:编写一个程序,输入学生人数和每个人的成绩,计算平均成绩。 ######注意:当输入的学生人数小于等于0时,输出平均成绩为0分! 例如:
相关知识


#include<stdio.h>
    int main()
    { 
      int a,i;
      double b,c=0;
      scanf("%d",&a);
      if(a<=0)
      {
          printf("the number of students:the scores:average=0.00\n");
      }
      else
          {
            for(i=1;i<=a;i++)
              {scanf(" %lf",&b);  /*%lf前有一个空格*/
            c=c+b;}    
          printf("the number of students:the scores:average=%.2f\n",c/a);
          }
       return 0;
    }