|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
这是错误的#include<stdio.h>
int main()
{long count = 0;int day1,day2;
int days[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int year1,year2;
int moth1,moth2;
printf("请输入你的生日(如1988-05-20):");
scanf("%d-%d-%d", &year1, &moth1, &day1);
printf("请输入今年日期(如2016-03-28):");
scanf("%d-%d-%d", &year2, &moth2, &day2);
while (year1 <= year2)
{
days[1] = (year1 % 400 == 0 || (year1 % 4 == 0 && year1 % 100 != 0)) ? 29 : 28;
while (moth1 <= 12)
{
while (day1 <= days[moth1 - 1])
{
if (year1 == year2 && moth1 == moth2 && day1 == day2)
{
goto FINISH; // 跳出多层循环才被迫用goto语句
}
day1++;
count++;
}
day1 = 0;
moth1++;
}
moth1 = 0;
year1++;
}
FINISH:printf("%d天",count);
return 0;
}
我弄了很久发现只要把int year1,year2;挪到int day1,day2;后面就对了,不然得到的是错误结果 想了很多遍也不知道为啥 |
|