#include <stdio.h>
void main()
{ int year,month,day; //定義三個整型變量表示年份,月份,天數
printf("input year and month:\n"); //要求輸入年份和月份
scanf("%d%d",&year,&month); //將輸入的年月放在變數中
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12: day=31; break; //31天的月份
case 4:
case 6:
case 9:
case 11: day=30; break; //30天的月份
case 2: if ((year % 4 == 0 && year % 100 != 0)
|| year % 400 == 0)
day = 29; //閏年二月28天
else day = 28; break; //非閏年29天
}
if (month < 1 || month >12) printf("error\n");//月份錯誤,error
else printf("這一月的天數是%d天\n",day); //輸出天數
#include <stdio.h>
void main()
{ int year,month,day; //定義三個整型變量表示年份,月份,天數
printf("input year and month:\n"); //要求輸入年份和月份
scanf("%d%d",&year,&month); //將輸入的年月放在變數中
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12: day=31; break; //31天的月份
case 4:
case 6:
case 9:
case 11: day=30; break; //30天的月份
case 2: if ((year % 4 == 0 && year % 100 != 0)
|| year % 400 == 0)
day = 29; //閏年二月28天
else day = 28; break; //非閏年29天
}
if (month < 1 || month >12) printf("error\n");//月份錯誤,error
else printf("這一月的天數是%d天\n",day); //輸出天數
}