c语言。输入年月日,分别判断三个数据是否在正确范围内(年的范围:1900至2014

如题所述

# include <stdio.h>
void main()
{
    int y, m, d;
    printf("请输入年月日:");
    scanf("%d %d %d", &y, &m, &d);
    if(1900 <= y <= 2014)
        printf("年份输入正确\n");
    else
        printf("年份输入错误\n");
    if(1 <= m <= 12)
        printf("月份输入正确\n");
    else
        printf("月份输入错误\n");
    if(1 <= d <=31)
        printf("日期输入正确\n");
    else
        printf("日期输入错误\n");
}

温馨提示:答案为网友推荐,仅供参考
第1个回答  2014-11-11
#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;
}本回答被网友采纳
相似回答