|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include<stdio.h>
int main()
{
int count = 0,count1 = 0;
int i,year1,mouth1,day1,year2,mouth2,day2,year3;
int days[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
//year3 = year1 + 80;
for(i = 0;i<1;i++)
{
printf("请输入你的生日:");
scanf("%d-%d-%d",&year1,&mouth1,&day1);
printf("请输入今年日期:");
scanf("%d-%d-%d",&year2,&mouth2,&day2);
//printf("%d%d%d今年%d%d%d",year1,mouth1,day1,year2,mouth2,day2);//调试专用
while(year1 <= year2)
{
days[1] = (year1 % 400 == 0 || (year1 % 4 == 0 && year1 % 100 != 0)) ? 29 : 28;
while(mouth1 <= 12)
{
while (day1 <= days[mouth1 - 1])
{
if (year1 == year2 && mouth1 == mouth2 && day1 == day2)
{
goto FINISH1; // 跳出多层循环才被迫用goto语句
}
day1++;
count1++;
}
day1 = 1;
mouth1++;
}
mouth1 = 1;
year1++;
}
}
FINISH1: printf("你在这个世界上总共生存了%d天\n", count1);
year3 = year1 + 80;
while(year1 <= year3)
{
days[1] = (year1 % 400 == 0 || (year1 % 4 == 0 && year1 % 100 != 0)) ? 29 : 28;
while(mouth1 <= 12)
{
while (day1 <= days[mouth1 - 1])
{
if (year1 == year3 && mouth1 == mouth2 && day1 == day2)
{
goto FINISH2; // 跳出多层循环才被迫用goto语句
}
day1++;
count++;
}
day1 = 1;
mouth1++;
}
mouth1 = 1;
year1++;
}
FINISH2: printf("如果能活到80岁,你还剩下%d天\n", count-count1);
printf("你已经使用了%.2f\%的生命,请珍惜剩下的时间.\n", (double)count1 / count * 100);//出问题的是这一行代码????
return 0;
}
|
-
这是官方结果
-
这是我编译得出的结果
-
这是出问题的那一行的原版,小甲鱼给的
|