|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 lpx9393 于 2020-2-6 00:24 编辑 #include <stdio.h>
int main()
{
int year1, month1, day1;
int year2, month2, day2;
long count = 0;
int days[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
printf("请输入你的生日(如2001-01-21):");
scanf("%d-%d-%d", &year1, &month1, &day1);
printf("请输入今天日期(如2020-02-05):");
scanf("%d-%d-%d", &year2, &month2, &day2);
while(year1 <= year2)
{
if(year1 % 400 == 0 || (year1 % 100 != 0 && year1 % 4 == 0))
{
days[1] = 29;
}
while(month1 <= 12)
{
while(day1 <= days[month1 - 1])
{
if(year1 == year2 && month1 == month2 && day1 == day2)
{
goto END;
}
day1++;
count++;
}
}
day1 = 1;
month1++;
}
month1 = 1;
year1++;
END:printf("你在这个世界总共生活了%d天\n", count);
return 0;
}
本帖最后由 XiaoPaiShen 于 2020-2-6 04:31 编辑
不懂c 语言,但感觉应该这样写,你运行一下看看对不对,我不知 c 如何运行 #include <stdio.h>
int main()
{
int year1, month1, day1;
int year2, month2, day2;
long count = 0;
int days[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
printf("请输入你的生日(如2001-01-21):");
scanf("%d-%d-%d", &year1, &month1, &day1);
printf("请输入今天日期(如2020-02-05):");
scanf("%d-%d-%d", &year2, &month2, &day2);
while(year1 <= year2)
{
if(year1 % 400 == 0 || (year1 % 100 != 0 && year1 % 4 == 0))
{ days[1] = 29; }
while(month1 <= 12)
{
while(day1 <= days[month1 - 1])
{
if(year1 == year2 && month1 == month2 && day1 == day2)
{ goto END; }
day1++;
count++;
}
day1 = 1;
month1++;
}
month1 = 1;
year1++;
}
END:printf("你在这个世界总共生活了%d天\n", count);
return 0;
}
|
|