S1E18生命计算器
#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 = 29;
// }
days = (year1 % 400 == 0 || (year1 % 4 == 0 && year1 % 100 != 0)) ? 29 : 28;
while (mon1 <= 12)
{
while (day1 <= days)
{
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)) 谢谢{:10_266:}
页:
[1]