为什么运行后只会输出生产了0天(s1e17~18的课后作业)
#include <stdio.h>int main ()
{
int year1,year2,month1,month2,day1,day2;
int count=0,i=0,year;
int days[]={31,28,31,30,31,30,31,31,30,31,30,31};
printf("请输入你的生日(如1988-05-20):");
scanf("%d-%d-%d",&year1,&month1,&day1);
printf("请输入今年日期(如2016-03-28):");
scanf("%d-%d-%d",&year2,&month2,&day2);
while(year1<=year2)
{
year=year1++;
}
for (i=0;year1<=year2;i++,month1=1)
{
days=(year%400==0||(year%4==0&&year%100!=0))?29:28;
for (;month1<=12;month1++,day1=1)
{
for(;day1<=days;day1++,count++)
{
if (year1==year2&&month1==month2&&day1==day2)
{
goto FINSH;
}
}
}
}
FINSH: printf("你在世界上总共生存粒%d天\n",count);
return 0;
}
先把思路说出来
顺便少用goto,直接写在最后一个if的缩进里就行 qiuyouzhi 发表于 2020-2-11 16:55
先把思路说出来
顺便少用goto,直接写在最后一个if的缩进里就行
题目:写一个生命计算器,要求用户输入生日,显示他在这个世界上活了多少天?
页:
[1]