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

如题所述

第1个回答  2017-10-29
#include<stdio.h>
#include<stdlib.h>

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);
}本回答被提问者采纳

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网