今日份

//读取一系列数据,每个数据表示每日的最低温度,然后打印统计的总天数和最低温度在O度以下的天数占总天数的百分比
//scanf()读取温度值,while每迭代一次,就递增计数器增加天数,其中if语句负责判断0度以下的温度并单独相应的天数
#include<stdio.h>
int main()
{
	//变量有哪些cold_days all_days 
	const int FREEZING = 0;
	float temperature;
	int cold_days = 0;
	int all_days = 0;

	printf("Enter the list of daily low temperatures.\n");
	printf("Use Clesius,and enter q to quit.\n");
	while (scanf("%f", &temperature) == 1)
	{
		all_days++;
		if (temperature < FREEZING)
			cold_days++;
	}
	if (all_days != 0)
		printf("%d days total:%0.1f%% were below temperature.\n",
			all_days, 100.0*(float)cold_days / all_days);
	if (all_days == 0)
		printf("No date enter!\n");
	return 0;
}

猜你喜欢

转载自blog.csdn.net/AKG420/article/details/88395736