题目为:
分析题目一下: 这个我先把题目意思看懂,1921年7月23日中午12点到7月31日晚上12点为八天半和2020年七月1日中午12点这里为半天一共九天。我就先定义long long count=9;这样就解了一半问题了,先用for循环嵌套,用它switch来判断月,是否为闰年,思路就这样。 看以下程序:
#include<stdio.h>
int main()
{int year;
int month;
int day;
long long count=9;
int m,n,temp1,temp2;
for(year=1921;year<2021;year++)
{
switch(year)
{case 1921:temp1=8;temp2=1;m=12;break;
case 2020:temp1=1;temp2=1;m=6;break;
default:temp1=1;m=12;temp2=1;break;
}
for(month=temp1;month<=m;month++)
{switch(month)
{case 1:case 3:case 5:case 7:
case 8:case 10:case 12: n=31;break;
case 4:case 6:case 9:case 11: n=30;break;
case 2:
if((year%100!=0)&&(year%4==0)||(year%400==0)) n=29;
else n=28;
break;
}
for(day=temp2;day<=n;day++)
{
count++;
}
}
}
count*=24*60;
printf("一共为%lld分钟",count);
return 0;
}
运行结果为: 谢谢大家观看后,希望对你有点帮助,有不足请指教一下。