开发环境为Dev C++
思路:
1、先定义好年、月
2、判断年份是否为闰年
3、不同月份的天数为多少
代码如下:
#include<stdio.h>
int main(void)
{
int year,month;
printf("input year:");
scanf("%d",&year);
printf("input month:");
scanf("%d",&month);
switch(month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
{
printf("The number of days in the month is 31 days.");
break;
}
case 4:
case 6:
case 9:
case 11:
{
printf("The number of days in the month is 30 days.");
break;
}
case 2:
if(year%4==0&&year%100!=0||year%400==0) //判断是否为闰年
printf("The number of days in the month is 29 days.");
else
printf("The number of days in the month is 28 days.");
default:
printf("Not this month");
}
return 0;
}
该博客展示了一个用C++编写的程序,它接收用户输入的年份和月份,然后根据输入判断该月份的天数。程序考虑了闰年的条件,正确地输出了不同月份的天数。对于2月,程序会根据闰年规则决定是28天还是29天。
4124

被折叠的 条评论
为什么被折叠?



