为什么我的程序他没有反应,也没有报错,然后也无法退出
本帖最后由 向舒 于 2021-6-7 19:10 编辑程序长这样
#include<stdio.h>
int main()
{
long count = 0;//count用于存放一共活了多少天
int year1,year2;//year1是你的生日年份,year2是今天的年份
int month1,month2;//与上同义
int day1,day2;
int days[] = {31,28,31,30,31,30,31,31,30,31,30,31};
printf("请输入你的生日(如2000-01-01):");
scanf("%d-%d-%d",&year1,&month1,&day1);
printf("请输入今年日期(如2000-01-01):");
scanf("%d-%d-%d",&year2,&month2,&day2);
while(year1<=year2)
{
days = (year1%400 == 0||(year1%4 == year1%10 != 0))?29:28;
while(month1 <= 12)
{
while(day1 <= days)
{
if(year1 == year2&& month1 == month2 && day1 ==day2)
{
goto FINISH;//为跳出多层循环才被迫用个哦goto语句
}
day1 = 1;
count++;
}
day1 = 1;
month1++;
}
month1 = 1;
year1++;
}
FINISH:printf("你在这个世界上总共生存了%d天\n",count);
return 0;
}
小甲鱼的原程序是这样的
#include <stdio.h>
int main()
{
long count = 0; // count用于存放一共活了多少天
int year1, year2; // year1是你的生日年份,year2是今天的年份
int month1, month2;
int day1, day2;
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)
{
days = (year1 % 400 == 0 || (year1 % 4 == 0 && year1 % 100 != 0)) ? 29 : 28;
while (month1 <= 12)
{
while (day1 <= days)
{
if (year1 == year2 && month1 == month2 && day1 == day2)
{
goto FINISH; // 跳出多层循环才被迫用goto语句
}
day1++;
count++;
}
day1 = 1;
month1++;
}
month1 = 1;
year1++;
}
FINISH: printf("你在这个世界上总共生存了%d天\n", count);
return 0;
}
找不到哪里错了
本帖最后由 向舒 于 2021-6-7 20:02 编辑
我找到了,谢谢帮忙{:5_91:} ctrl + c 死循环?建议goto语句尽量少用
页:
[1]