三九宝宝网宝宝百科年龄段培养

编写函数得到某年一个月的天数

01月06日 编辑 39baobao.com

#include

int main(int argc, constchar * argv[])

{

int year=0,month=0,day=0,result=0;

printf("请输入年份:(年月日之间用逗号隔开)");

scanf("%d,%d,%d",&year,&month,&day);

if(year/400||((year/4)&(!(year/100)))){

printf("这一年是闰年,");

switch (month) {

case1:

result=day;break;

case 2:

result=31+day;break;

case3:

result=31+29+day;break;

case4:

result=31+29+31+day;break;

case5:

result=31+29+31+30+day;break;

case6:

result=31+29+31+30+31+day;break;

case7:

result=31+29+31+30+31+30+day;break;

case8:

result=31+29+31+30+31+30+31+day;break;

case9:

result=31+29+31+30+31+30+31+31+day;break;

case10:

result=31+29+31+30+31+30+31+31+30+day;break;

case11:

result=31+29+31+30+31+30+31+31+30+31+day;break;

case12:

result=31+29+31+30+31+30+31+31+30+31+30+day;break;

default:

break;

}

}

else{

printf("这一年不是闰年。");

switch (month) {

case1:

result=day;break;

case 2:

result=31+day;break;

case3:

result=31+30+day;break;

case4:

result=31+30+31+day;break;

case5:

result=31+30+31+30+day;break;

case6:

result=31+30+31+30+31+day;break;

case7:

result=31+30+31+30+31+30+day;break;

case8:

result=31+30+31+30+31+30+31+day;break;

case9:

result=31+30+31+30+31+30+31+31+day;break;

case10:

result=31+30+31+30+31+30+31+31+30+day;break;

case11:

result=31+30+31+30+31+30+31+31+30+31+day;break;

case12:

result=31+30+31+30+31+30+31+31+30+31+30+day;break;

default:

break;

}

}

printf("这一天是这一年的第%d天!\n",result);

return0;

}

推荐阅读
图文推荐