例3-3 统计成绩

统计成绩

程序核心——循环语句、判断语句的镶嵌

程序

#include<stdio.h>
int main()
{
	int count,i,n;
	double grade,total;
	//count 存放不及格人数,n 人数,grade 输入成绩,total 成绩和
	printf("Enter n:");
	scanf("%d",&n);
	count=0;
	total=0;
	for(i=1;i<=n;i++)
	{
		printf("Enter grade #%d:",i);
		scanf("%lf",&grade);
		total=total+grade;
		if(grade<60)
			count++;
	}
	printf("Grade average=%.2f\n",total/n);
	printf("Number of failures=%d\n",count);
	return 0;
}

结果

Enter n:4
Enter grade #1:67
Enter grade #2:54
Enter grade #3:88
Enter grade #4:73
Grade average=70.50
Number of failures=1

--------------------------------
Process exited after 22.61 seconds with return value 0
请按任意键继续. . .

分析

重点:判断语句,注意判断、循环条件是否存在遗漏

posted on 2019-03-15 20:41  凯*凯  阅读(95)  评论(0编辑  收藏  举报

导航