C语言17课的课后作业
#include<stdio.h>int main(void)
{
int year1,month1,day1,year2,day2,month2,day;
printf("请输入你的生日(如1988-05-20):");
scanf("%d-%d-%d",&year1,&month1,&day1);
printf("请输入现在的日期(如2016-03-28:)");
scanf("%d-%d-%d",&year2,&month2,&day2);
int x[]={31,28,31,30,31,30,31,31,30,31,30,31};
while(year1<=year2)
{
x=(year1%4==0)?29:28;
while(month1<=12)
{ day1=1;
while(day1<=x)
{
while(day1==day2&&year1==year2&&month1==month2)
{
goto finsh;
}
day1++;
day++;
}
}
year1++;
month1=1;
}
finsh:printf("你出生到现在活了%d天",day);
return 0 ;
}
// 这里数组越界了!!! 当month1 = 12时, x; 应该是while(day1 <= x);
while(day1<=x)
{
while(day1==day2&&year1==year2&&month1==month2)
{
goto finsh;
}
day1++;
day++;
}
} 闰年的判断也有一点问题哦, 建议百度看看闰年如何判断的{:10_282:}
页:
[1]