42: 统计不及格人数

42 统计不及格人数

作者: Turbo时间限制: 1S章节: 一维数组

问题描述 :

输入某班学生某门课的成绩(最多不超过40人),用函数编程统计不及格人数并输出。

输入说明 :

分两行输入,第一行为一个非负整数n,表示该班学生人数。第二行为n个成绩(可为实数),分数之间以一个空格分隔。如果n等于0,则无第二行。

输出说明 :

输出一个整数,表示该班不及格人数。行首与行尾无多余空格。

输入范例 :
2
59 60
输出范例 :
1

代码:

#include <stdio.h>
int main()
{
	int n;
	double score;
	int num = 0;
	while (scanf("%d", &n) != EOF)
	{
		if (n == 0);
		else
		{
			for (int i = 0; i < n; i++)
			{
				scanf("%lf", &score);
				if (score < (double)60)
				{
					num++;
				}
			}
		}
		printf("%d
", num);
	}
	return 0;
}
Yesterday is history,tomorrow ismystery,but today is a gift!That why it is called Present!
原文地址:https://www.cnblogs.com/VictorierJwr/p/12487515.html