c语言。输入年月日,分别判断三个数据是否在正确范围内(年的范围:1900至2014
答案:2 悬赏:70 手机版
解决时间 2021-01-31 23:42
- 提问者网友:骨子里的高雅
- 2021-01-31 02:27
c语言。输入年月日,分别判断三个数据是否在正确范围内(年的范围:1900至2014
最佳答案
- 五星知识达人网友:零点过十分
- 2021-01-31 03:48
#include "stdio.h"
void main()
{
int year, month, day,maxday;
printf("请输入年月日:\n");
scanf("%d%d%d", &year, &month, &day);
if(year>=1900&&year<=2014)
printf("年份输入正确\n");
else
printf("年份输入错误\n");
if(month>=1&&month<=12)
printf("月份输入正确\n");
else
printf("月份输入错误\n");
switch(month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
maxday = 31;
break;
case 4:
case 6:
case 9:
case 11:
maxday = 30;
break;
case 2:
if (year%4==0&&year%100!=0||year%400==0)
maxday = 29;
else
maxday = 28;
break;
default:
break;
}
if (day<=maxday)
{
printf("日期输入正确\n");
}
else
printf("日期输入错误\n");
return;
}
void main()
{
int year, month, day,maxday;
printf("请输入年月日:\n");
scanf("%d%d%d", &year, &month, &day);
if(year>=1900&&year<=2014)
printf("年份输入正确\n");
else
printf("年份输入错误\n");
if(month>=1&&month<=12)
printf("月份输入正确\n");
else
printf("月份输入错误\n");
switch(month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
maxday = 31;
break;
case 4:
case 6:
case 9:
case 11:
maxday = 30;
break;
case 2:
if (year%4==0&&year%100!=0||year%400==0)
maxday = 29;
else
maxday = 28;
break;
default:
break;
}
if (day<=maxday)
{
printf("日期输入正确\n");
}
else
printf("日期输入错误\n");
return;
}
全部回答
- 1楼网友:枭雄戏美人
- 2021-01-31 05:07
# include
void main()
{
int y, m, d;
printf("请输入年月日:");
scanf("%d %d %d", &y, &m, &d);
if(1900 <= y <= 2014)
printf("年份输入正确 ");
else
printf("年份输入错误 ");
if(1 <= m <= 12)
printf("月份输入正确 ");
else
printf("月份输入错误 ");
if(1 <= d <=31)
printf("日期输入正确 ");
else
printf("日期输入错误 ");
}
void main()
{
int y, m, d;
printf("请输入年月日:");
scanf("%d %d %d", &y, &m, &d);
if(1900 <= y <= 2014)
printf("年份输入正确 ");
else
printf("年份输入错误 ");
if(1 <= m <= 12)
printf("月份输入正确 ");
else
printf("月份输入错误 ");
if(1 <= d <=31)
printf("日期输入正确 ");
else
printf("日期输入错误 ");
}
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯