每周一练(3)答案
来自@人造人 的答案#include <stdio.h>
int main(void)
{
int day[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int Leap_Feb = 29;
int year, month;
printf("请输入年份和月份:\n");
while(1) {
if(scanf("%d %d", &year, &month) == 2) break;
while(getchar() != '\n');
printf("年份或月份输入错误,请重新输入!\n");
}
/*
scanf("%d %d", &year, &month);
while ( year<0 || month<1 || month >12 )
{
printf("年份或月份输入错误,请重新输入!\n");
scanf("%d %d", &year, &month);
}
*/
if ( !year%400 || (!year&4 && !year%100) )
{
if ( 2 == month )
printf("%d\n", Leap_Feb);
else
printf("%d\n", day);
}
else
printf("%d\n", day);
return 0;
} 感谢大佬的分享!!! bwzxhjy 发表于 2021-8-29 20:09
感谢大佬的分享!!!
.... 有一说一哈,25行闰年的判断写法很酷,但是不认可,因为很糙。
页:
[1]