From f6b797a44f344ac89c8ab847c8138ed5964f3c22 Mon Sep 17 00:00:00 2001 From: pfvx5hjso <6687900@qq.com> Date: Thu, 5 Oct 2023 15:10:43 +0800 Subject: [PATCH] ADD file via upload --- example2-3.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 example2-3.c 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); +}