c语言编程:编写函数1实现判断是不是闰年,编写函数2用于输出某年某月的天数(用的switch语句)

2024-12-31 11:09:22
推荐回答(1个)
回答1:

#include
#include

int main()
{
void daysinmonth(int y,int m);
int y,m;

scanf("%d %d",&y,&m);
daysinmonth(y,m);
system("PAUSE");
return EXIT_SUCCESS;
}
int isleapyear(int y)
{
return ((0==y%4 && 0!=y%100) || 0==y%400);
}
void daysinmonth(int y,int m)
{
int days;

switch(m)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
days=31;
break;
case 2:
days=28;
if(isleapyear(y))
{
days++;
}
break;
case 4:
case 6:
case 9:
case 11:
days=30;
break;
}
printf("%d年%d月有%d天\n",y,m,days);
}