中易网

输入年份和月份,求该月有多少天?

答案:2  悬赏:10  
解决时间 2021-01-17 23:29
  • 提问者网友:夢醒日落
  • 2021-01-17 20:03
输入年份和月份,求该月有多少天?
最佳答案
  • 二级知识专家网友:蕴藏春秋
  • 2021-01-17 21:22
#include
#include
int leap(int y);
int a[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int main(){
int y,m;
scanf("%d%d",&y,&m);
if(leap(y))a[2]=29;
else a[2]=28;
printf("%d年%d月共有%d天\n",y,m,a[m]);
//system("pause");
return 0;
}
int leap(int y){
int i;
if((y%4==0&&y%100!=0)||y%400==0)i=1;
else i=0;
return i;
}
全部回答
  • 1楼网友:枭雄戏美人
  • 2021-01-17 22:21
#include
void main()
{
int year,month;
printf("Please input the year and the month:\n");
scanf("%d%d",&year,&month);
if(month>12 || month<1)
printf("Input error!\n");
switch(month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12: printf("the month has 31 days.\n"); break;
case 4:
case 6:
case 9:
case 11: printf("the month has 30 days.\n"); break;
case 2:
{
if(year % 4 == 0)
printf("the month has 29 days.\n");
else
printf("the month has 28 days.\n");
}
break;
}
}
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息!
大家都在看
推荐信息