满意答案
c294549
2014.11.01
采纳率:46% 等级:6
已帮助:557人
#include "stdio.h"
int main()
{
int year,month,day;
int sign=0,dayvalid;
printf("请输入年5261月日:\n");
scanf("%d,%d,%d",&year,&month,&day);
if ((year%4==0&&year%100!=0)|4102|year%400==0)
{
1653sign =1;
}
if (month>=1&&month<=12)
{
switch (month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
dayvalid = 31;
break;
case 4:
case 6:
case 9:
case 11:
dayvalid = 30;
break;
case 2:
if (sign ==1)
dayvalid = 29;
else
dayvalid = 28;
break;
default:
break;
}
if (!(day >0&&day <=dayvalid))
{
printf("日期格式错误\n");
return 2;
}
}
else
{
printf("月份格式错误:\n");
return 1;
}
printf("日期格式正确\n");
return 0;
}
02分享举报