|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include<stdio.h>
int main()
{
int year1,year2,year3;
int month1,month2,month3;
int day1,day2,day3;
int days[]={31,28,31,30,31,30,31,31,30,31,30,31};
long count1=0,count2;
printf("请输入您的出生日期(y-m-d):");
scanf("%d-%d-%d",&year1,&month1,day1);
printf("请输入今天的日期(y-m-d):");
scanf("%d-%d-%d",&year2,&month2,&day2);
year3=year1+80;
month3=month1;
day3=day1;
while(1)
{
days[1]=year1%400==0||year1%4==0&&year1%100!=0?29:28;
while(month1<=12)
{
while(day1<=days[month1-1])
{
if(day1==day2&&month1==month2&&year1==year2)
{
count2=count1;
printf("您一共活了%d天",count2);
}
if(day1==day3&&month1==month3&&year1==year3)
{
printf("如果您能活到80岁,您剩下%d天的寿命",count1-count2);
printf("您已经使用了%.2f%%的生命,请好好珍惜剩下的时间",(double)count2/count1*100);
return 0;
}
day1++;
count1++;
}
day1=1;
month1++;
}
month1=1;
year1++;
}
}
本帖最后由 isdkz 于 2022-2-26 22:58 编辑
第11行, day1 漏了一个 &#include<stdio.h>
int main()
{
int year1,year2,year3;
int month1,month2,month3;
int day1,day2,day3;
int days[]={31,28,31,30,31,30,31,31,30,31,30,31};
long count1=0,count2;
printf("请输入您的出生日期(y-m-d):");
scanf("%d-%d-%d",&year1,&month1,&day1); // 这里的 day1 漏了一个 &
printf("请输入今天的日期(y-m-d):");
scanf("%d-%d-%d",&year2,&month2,&day2);
year3=year1+80;
month3=month1;
day3=day1;
while(1)
{
days[1]=year1%400==0||year1%4==0&&year1%100!=0?29:28;
while(month1<=12)
{
while(day1<=days[month1-1])
{
if(day1==day2&&month1==month2&&year1==year2)
{
count2=count1;
printf("您一共活了%d天",count2);
}
if(day1==day3&&month1==month3&&year1==year3)
{
printf("如果您能活到80岁,您剩下%d天的寿命",count1-count2);
printf("您已经使用了%.2f%%的生命,请好好珍惜剩下的时间",(double)count2/count1*100);
return 0;
}
day1++;
count1++;
}
day1=1;
month1++;
}
month1=1;
year1++;
}
}
|
|