admin 管理员组

文章数量: 1087833


2024年4月25日发(作者:apache 虚拟主机配置详解)

读入一个年份和月份,打印出该月有多少天(考虑闰年),用switch语句编程。

#include

main()

{

int year, month;

printf("Input year,month: ");

scanf("%d, %d", &year, &month);/*输入相应的年和月*/

switch (month)

{

case 1:

case 3:

case 5:

case 7:

case 8:

case 10:

case 12:

printf("31 daysn");

1 / 3

break;

case 2:

if((year % 4== 0 && year % 100 != 0)||(year % 400 == 0)){

printf("29 daysn");/*闰年的2月有29天*/}

else

{

printf("28 daysn");/*平年的2月有28天*/}

break;

case 4:

case 6:

case 9:

case 11:

printf("30 daysn");

break;

default:

printf("Input error!n");

}

2 / 3

}

3 / 3


本文标签: 虚拟主机 月份 打印 年份 语句