C语言中先输入一个日期然后判断是否合法若不合法则继续输入至合法的程序(分年月日输入)

2024-12-04 14:54:21
推荐回答(1个)
回答1:

#include
int main()
{int y,m,d,a[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
do{printf("Please enter a date(yyyy m d):");
scanf("%d%d%d",&y,&m,&d);
}while(y<1||m<棚仿哗1||m>12||d<大凳1||d>链行a[m]+(m==2)&(y%4==0&&y%100>0||y%400==0));
printf("%d-%d-%d is a valid date!\n",y,m,d);
return 0;
}