**
怎么判断输入的年 月 日 是否合法呢?
**
#include<stdio.h>
int run(int year)
{
if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0))
return 1;
return 0;
}
int pan(int year, int mon, int day)
{
if (year < 0 || mon <= 0 || mon > 12 || day <= 0 || day > 31)
return 0;
if (1 == mon || 3 == mon || 5 == mon || 7 == mon || 8 == mon || 10 == mon || 12 == mon)
{
return 1;
}
if ((4 == mon || 6 == mon || 9 == mon || 11 == mon )&& day > 30)
return 0;
if (run(year))
{
if (2 == mon && (28 == day || 30 == day || 31 == day))
return 0;
return 1;
}
else
{
if (2 == mon && (29 == day || 30 == day || 31 == day))
return 0;
return 1;
}
}
int main()
{
int year = 0;
int mon = 0;
int day = 0;
printf("请分别输入年月日,以空格隔开: ");
scanf("%d %d %d", &year, &mon, &day);
printf("%s\n", 1 == run(year) ? "是闰年" : "不是闰年");
printf("%s\n", 1 == pan(year, mon, day) ? "合法" : "不合法");
return 0;
}
***作者:邹氏情歌cium***