int year = 0,month = 0,day = 0; int i= 1; int febDay = 28; while(i){ printf("按xxxx-xx-xx的形式输入生日:"); scanf("%d-%d-%d",&year,&month,&day); BOOL res1=year%400==0||(year%4==0&&year%100!=0); if (res1) { febDay=29; } switch (month) { case 2:{ if (day>=1&&day<=febDay) { printf("合法\n"); }else{ printf("不合法\n"); continue; } break;//不再执行其他case } case 1: case 3: case 5: case 7: case 8: case 10: case 12:{ if (day>=1&&day<=31) { printf("合法\n"); }else{ printf("不合法\n"); continue; } break; } case 4: case 6: case 9: case 11:{ if (day>=1&&day<=30) { printf("合法\n"); } else { printf("不合法\n");continue; }break; } default:{ printf("不合法\n");continue; } } break;//跳出while循环 }
时间: 2024-10-09 01:13:31