一.程序功能
将输入的天气温度,进行零下摄氏度的比例换算
二、代码
#include<stdio.h>
int main(void)
{
const int FREEZING=0;
float temperature;
int cold_days=0;
int all_days=0;
printf("please enter the ten days'temperature.\n");
while(scanf("%f",&temperature)==1)
{
all_days++;
if(temperature<FREEZING)
cold_days++;
}
if (all_days!=0)
printf("%d days total:%.lf%% were below freezing.\n",all_days,100.0*(float) cold_days/all_days);
if(all_days=0)
printf("no data entered!\n");
return 0;
}
三、实验结果