diff --git a/example2-3.c b/example2-3.c new file mode 100644 index 0000000..7652a37 --- /dev/null +++ b/example2-3.c @@ -0,0 +1,23 @@ +/*example2-3.c*/ +#include +main() +{ int year,month,day; + + printf("Enter year & month:"); + scanf("%d%d",&year,&month); /*输入年份和月份*/ + if (month==2) /*判断输入的月份是否为二月份*/ + if ((year%4==0&&year%100!=0)||(year%400==0)) /*是二月份,判断是否为闰年*/ + day=29; + else day=28; + else /*不是二月份,则区分判断各月的天数*/ + switch (month) + { + case 1: case 3: + case 5: case 7: + case 8: case 10: + case 12: day=31; break; /*多个case公用一个语句*/ + case 4: case 6: + case 9: case 11: day=30; break; + } + printf("year=%d month=%d day=%d\n",year,month,day); +}