求C语言基础代码

[复制链接]
查看11 | 回复2 | 2011-10-31 11:47:41 | 显示全部楼层 |阅读模式
4.输入一个年份和该年中的一个月份,输出该年该月份有多少天,例如,输入20113,输出2011年3月有31天。
回复

使用道具 举报

千问 | 2011-10-31 11:47:41 | 显示全部楼层
C菜鸟助手成员tonytvb为你解答(如有疑问请hi我或向我的团队提问):#includestdio.hintmain(){intyear,month;scanf(\"%d%d\",if(month12||month1){printf(\"wronginput!\");return-1;}printf(\"year:%d,month:%d\\n\",year,month);if(month==1||month==3||month==5||month==7||month==8||month==10||month==12)printf(\"31days\\n\");elseif(month==4||month==6||month==9||month==11)printf(\"30days\\n\");elseif((month==2elseprintf(\"28days\\n\");return0;}
回复

使用道具 举报

千问 | 2011-10-31 11:47:41 | 显示全部楼层
#includestdio.h#includestdlib.hintisLeepYear(intyear){return(year%4==0}intgetDaysOfMonth(intyear,intmonth){intnDays[13]={0,31,28,31,30,31,30,31,31,30,31,30,31},nDay;if(year0||month1||month12)return0;nDay=nDays[month];if(isLeepYear(year)returnnDay;}intmain(){intyear,month;printf(\"请输入年份和月份:\\n\");scanf(\"%d%d\",printf(\"%d年%d月有%d天\\n\",year,month,getDaysOfMonth(year,month));system(\"pause\");return0;}赞同
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行