用C语言编写程序,急!
答案:3 悬赏:0 手机版
解决时间 2021-05-05 13:44
- 提问者网友:姑娘长的好罪过
- 2021-05-05 06:04
用C语言编写程序:输入一个学生的生日(年y0月m0日d0),并输入当前日期(年y1月m1日d1),输出该学生的实际年龄。
最佳答案
- 五星知识达人网友:鸠书
- 2021-05-05 06:22
#include<stdio.h>
int main()
{
int y0,m0,d0;
int y1,m1,d1;
printf("请输入生日:\n");
printf("年:");
scanf("%d",&y0);
printf("\n月:");
scanf("%d",&m0);
printf("\n日:");
scanf("%d",&d0);
sign:
printf("\n请输入当前日期:");
printf("\n年:");
scanf("%d",&y1);
printf("\n月:");
scanf("%d",&m1);
printf("\n日:");
scanf("%d",&d1);
if((y1<y0)||m0>12||m1>12||d0>30||d1>30)
{
printf("\nERROR!!!");
goto sign;
}
printf("你的实际年龄是:");
printf("%d岁%d月%d天",y1-y0,(m1-m0+12)%12,(d1-d0+30)%30);
getchar();getchar();
}
int main()
{
int y0,m0,d0;
int y1,m1,d1;
printf("请输入生日:\n");
printf("年:");
scanf("%d",&y0);
printf("\n月:");
scanf("%d",&m0);
printf("\n日:");
scanf("%d",&d0);
sign:
printf("\n请输入当前日期:");
printf("\n年:");
scanf("%d",&y1);
printf("\n月:");
scanf("%d",&m1);
printf("\n日:");
scanf("%d",&d1);
if((y1<y0)||m0>12||m1>12||d0>30||d1>30)
{
printf("\nERROR!!!");
goto sign;
}
printf("你的实际年龄是:");
printf("%d岁%d月%d天",y1-y0,(m1-m0+12)%12,(d1-d0+30)%30);
getchar();getchar();
}
全部回答
- 1楼网友:第幾種人
- 2021-05-05 06:48
//对年份是否为闰年做了对应判断处理
#include <stdio.h>
int judgement ( int year, int month, int day) { if (month<=0||month>12) { return 1; } else if (month ==2) { if (year%100) { if(year%4) { if (day<=0||day>28) return 2; } else { if (day<=0||day>29) return 2; } } else { if(year%400) { if (day<=0||day>28) return 2; } else { if (day<=0||day>29) return 2; } } } else if (month ==4||month ==6 ||month ==9||month ==11 ) { if (day<=0||day>30) return 2; } else { if (day<=0||day>31) return 2; } return 0; } int main() { int year,month,day,now_year,now_month,now_day,ret; printf("input the birthday:(y-m-d)\n"); scanf("%d-%d-%d",&year,&month,&day); ret=judgement(year,month,day); if (ret ==1) { printf ("month input error!\n"); return 1; } else if (ret ==2) { printf ("day input error!\n"); return 2; } printf("input the now date:(y-m-d)\n"); scanf("%d-%d-%d",&now_year,&now_month,&now_day); ret=judgement(now_year,now_month,now_day); if (ret ==1) { printf ("month input error!\n"); return 1; } else if (ret ==2) { printf ("day input error!\n"); return 2; } if (now_month>month) printf("%d years old!\n",now_year-year); else if (now_month==month) if (now_day>=day) printf("%d years old!\n",now_year-year); else printf("%d years old!\n",now_year-year-1); else printf("%d years old!\n",now_year-year-1); getchar(); return 0; }- 2楼网友:笑迎怀羞
- 2021-05-05 06:39
兄弟你好:我不知道在妈妈肚子里算不算一岁开始下面是我写的你看看
#include "stdio.h" #include "conio.h"
main() { int year,month,day;//生日年月日 int nyear,nmonth,nday;//现在年月日 int N; printf("please input your birthday\n"); scanf("%d%d%d",&year,&month,&day); printf("please input the time now\n"); scanf("%d%d%d",&nyear,&nmonth,&nday); N=nyear-year+1; if(nmonth<month) N--; else if(nmonth==month) if(nday<day) N--; printf("%d",N); getch(); }
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯