用switch语句从键盘输入一个月份,自动显示该月份的英文名称!C语言的
4个回答
展开全部
#include <stdio.h>
int main()
{
int m = 0;
printf("请输入一个月份(1~12):");
scanf("%d",&m)
switch(m) {
case 1:
printf("January\n");
break;
case 2:
printf("February\n");
break;
case 3:
printf("March\n");
break;
case 4:
printf("April\n");
break;
case 5:
printf("May \n");
break;
case 6:
printf("June \n");
break;
case 7:
printf("July\n");
break;
case 8:
printf("August \n");
break;
case 9:
printf("September \n");
break;
case 10:
printf("October \n");
break;
case 11:
printf("November \n");
break;
case 12:
printf("December\n");
break;
defualt:
printf("Error \n");
break;
}
return 0;
}
追问
蟹蟹
2015-11-21 · 知道合伙人教育行家
天雨下凡
知道合伙人教育行家
向TA提问 私信TA
知道合伙人教育行家
采纳数:17564
获赞数:65159
爱电脑、爱数学、爱音乐; 熟悉VB、C/C++、JAVA; EXCEL与VBA有所研究…… 数学,一些会,一些被忘却……
向TA提问 私信TA
关注
展开全部
#include<stdio.h>
int main(void)
{
int n;
printf("请输入月份数字: ");
scanf("%d",&n);
switch(n)
{
case 1:
printf("January\n");
break;
case 2:
printf("February\n");
break;
case 3:
printf("March\n");
break;
case 4:
printf("April\n");
break;
case 5:
printf("May\n");
break;
case 6:
printf("June\n");
break;
case 7:
printf("July\n");
break;
case 8:
printf("August\n");
break;
case 9:
printf("September\n");
break;
case 10:
printf("October\n");
break;
case 11:
printf("November\n");
break;
case 12:
printf("December\n");
break;
default:
printf("输入错误!");
break;
}
return 0;
}
int main(void)
{
int n;
printf("请输入月份数字: ");
scanf("%d",&n);
switch(n)
{
case 1:
printf("January\n");
break;
case 2:
printf("February\n");
break;
case 3:
printf("March\n");
break;
case 4:
printf("April\n");
break;
case 5:
printf("May\n");
break;
case 6:
printf("June\n");
break;
case 7:
printf("July\n");
break;
case 8:
printf("August\n");
break;
case 9:
printf("September\n");
break;
case 10:
printf("October\n");
break;
case 11:
printf("November\n");
break;
case 12:
printf("December\n");
break;
default:
printf("输入错误!");
break;
}
return 0;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
main()
{
while(1)
{
int a=1;
printf("\n请输入月份\n");
scanf("%d",&a);
switch(a)
{
case 1:
printf(" January");
break;
case 2:
printf(" February ");
break;
case 3:
printf("March");
break;
case 4:
printf("April ");
break;
case 5:
printf("May ");
break;
case 6:
printf("June");
break;
case 7:
printf("July");
break;
case 8:
printf(" August ");
break;
case 9:
printf("September");
break;
case 10:
printf("October");
break;
case 11:
printf(" November");
break;
case 12:
printf("December");
break;
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
int a;
scanf("%d",&a);
if(a < 0 || a > 12)
return ;
switch(a)
{
case 1: printf("%s","January");break;
case 2:printf("%s","February");break;
.
.
.
case12:printf("%s","December");break;
}
scanf("%d",&a);
if(a < 0 || a > 12)
return ;
switch(a)
{
case 1: printf("%s","January");break;
case 2:printf("%s","February");break;
.
.
.
case12:printf("%s","December");break;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询