|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 杀死庸俗 于 2022-2-27 18:04 编辑
为什么我这个算出来答案和小甲鱼的不同呀,不知道哪里有问题。小甲鱼算出来是10174天而我却是10195天
#include<stdio.h>
int main()
{
int day[]={31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int year1, year2;
int month1, month2;
int day1, day2;
long long int count=0;
printf("请输入你的生日:");
scanf("%d %d %d", &year1, &month1, &day1);
printf("请输入现在日期:");
scanf("%d %d %d", &year2, &month2, &day2);
for(year1; year1<=year2; year1++)
{
if(year1%400==0||year1%4==0&&year1%100!=0)
{
day[1]=29;
}
for(month1; month1<=12; month1++)
{
for(day1; day1<=day[month1-1]; day1++)
{
if(year1==year2&&month1==month2&&day1==day2)
{
goto life;
}
count++;
}
day1=1;
}
month1=1;
}
life: printf("共生活了%d天\n", count);
return 0;
}
这是我的代码
你这光记得闰年是 29 天,不记得平年 28天了 #include<stdio.h>
int main()
{
int day[]={31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int year1, year2;
int month1, month2;
int day1, day2;
long long int count=0;
printf("请输入你的生日:");
scanf("%d %d %d", &year1, &month1, &day1);
printf("请输入现在日期:");
scanf("%d %d %d", &year2, &month2, &day2);
for(year1; year1<=year2; year1++)
{
if(year1%400==0||year1%4==0&&year1%100!=0)
{
day[1]=29;
}
else
day[1]=28; // 记得换回来
for(month1; month1<=12; month1++)
{
for(day1; day1<=day[month1-1]; day1++)
{
if(year1==year2&&month1==month2&&day1==day2)
{
goto life;
}
count++;
}
day1=1;
}
month1=1;
}
life: printf("共生活了%d天\n", count);
return 0;
}
|
|