编写一个程序,从键盘上输入一组学生的分数,计算平均分数,并计算失败的学生人数。

Write a program to input the scores of a group of students from the keyboard, calculate the average score, and count the number of failed students.

#include<stdio.h>
int main()
{
	int sum,average,a,b,c,i;
	printf("输入完成时请输入一个随机的负数\n"); 
	printf("请输入学生成绩:");

	sum=0;
	average=0;
	a=0;//chengji
	b=0;//jigerenshu
	c=0;//bujigerenshu
	do{
		scanf("%d",&a);
		if(a>=0)
		{
			b++;
			sum=sum+a;
			if(a<60)
			c++;
			
		}
	}
	while(a>=0);
	average=sum/b;
	 printf("不及格人数为:%d\n",c);
	 printf("平均分:%d",average);
}

版权声明:本文为ASTeri原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。