马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include <stdio.h>
int main()
{
long count = 0; //计数存活天数
int year1, year2; //year1是生日年,year是今年
int mon1, mon2;
int day1, day2;
int days[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
printf("请输入你的生日(如 1988-05-20):");
scanf("%d-%d-%d", &year1, &mon1, &day1);
printf("请输入你的生日(如 2016-03-28):");
scanf("%d-%d-%d", &year2, &mon2, &day2);
while (year1 <= year2)
{
// if(year1 % 400 == 0 || (year1 % 4 == 0 && year1 & 100 != 0))
// {
// days[1] = 29;
// }
days[1] = (year1 % 400 == 0 || (year1 % 4 == 0 && year1 % 100 != 0)) ? 29 : 28;
while (mon1 <= 12)
{
while (day1 <= days[mon1-1])
{
if (year1 == year2 && mon1 == mon2 && day1 == day2)
{
goto FINISH;
}
day1 += 1;
count += 1;
}
day1 = 1;
mon1 += 1;
}
year1 += 1;
mon1 = 1;
}
FINISH: printf("你在这世界上总共生存了%d天!", count);
return 0;
}
将判断闰年的条件表达式换成if语句(注释掉的部分)时,为什么算出来的结果不一样,求解答。
if(year1 % 400 == 0 || (year1 % 4 == 0 && year1 & 100 != 0))
if(year1 % 400 == 0 || (year1 % 4 == 0 && year1 % 100 != 0))
|