6个回答
推荐于2017-09-09 · 知道合伙人教育行家
关注
展开全部
思路:可以通过switch语句判断最为合适。
参考代码:
#include<stdio.h>
int main()
{
int a;
scanf("%d",&a);
switch(a){
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:printf("31\n");break;
case 2:printf("29\n");break;
case 4:
case 6:
case 9:
case 11:printf("30\n");
}
return 0;
}
/*
5
31
*/
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include <stdio.h>
int main(void)
{
int month;
printf("please input the month number :");
scanf("%d", &month);
if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12)
{
printf("2003.%d has 31 days\n", month);
}
else if (month == 4 || month == 6 || month == 9 || month == 11)
{
printf("2003.%d has 30 days\n", month);
}
else if (month == 2)
{
printf("2003.%d has 28 days\n", month);
}
else
{
printf("Invalid month input !\n");
}
return 0;
}
int main(void)
{
int month;
printf("please input the month number :");
scanf("%d", &month);
if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12)
{
printf("2003.%d has 31 days\n", month);
}
else if (month == 4 || month == 6 || month == 9 || month == 11)
{
printf("2003.%d has 30 days\n", month);
}
else if (month == 2)
{
printf("2003.%d has 28 days\n", month);
}
else
{
printf("Invalid month input !\n");
}
return 0;
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include "stdio.h"
void main()
{
int m[12] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int a;
scanf("%d", &a);
printf("%d 月是%d 天\n", a, m[a - 1]);
}
void main()
{
int m[12] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int a;
scanf("%d", &a);
printf("%d 月是%d 天\n", a, m[a - 1]);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
scanf("%d",&i);
swich(i)
{
case 1: day = 31;
case 2: day = 28;
case12: day = 31;
}
printf("%d月有%d天\n",i,day);
swich(i)
{
case 1: day = 31;
case 2: day = 28;
case12: day = 31;
}
printf("%d月有%d天\n",i,day);
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询