C语言的问题,大家帮忙设计一个C语言程序,谢谢啦
设计一个进行数值月份向英文名称月份转换的C程序。即当用户输入一个数字月份时,输出其对应的英文月份名称。我是初学者,希望大家帮帮忙啦。。。...
设计一个进行数值月份向英文名称月份转换的C程序。即当用户输入一个数字月份时,输出其对应的英文月份名称。我是初学者,希望大家帮帮忙啦。。。
展开
4个回答
展开全部
#include "stdio.h"
main()
{
int num;
char arr[13][12]={"error!\n","January\n","February\n","Match\n","April\n","May\n","June\n","July\n","August\n","Sepetember\n","October\n","November\n","December\n"}; //定义二维数组
scanf("%d",&num);
if (num<1 || num>12) //加入容错
{
printf("%s",arr[0]);
}else
{
printf("%s",arr[num]); //输出英文月份
}
}
有问题请追问 满意请采纳
main()
{
int num;
char arr[13][12]={"error!\n","January\n","February\n","Match\n","April\n","May\n","June\n","July\n","August\n","Sepetember\n","October\n","November\n","December\n"}; //定义二维数组
scanf("%d",&num);
if (num<1 || num>12) //加入容错
{
printf("%s",arr[0]);
}else
{
printf("%s",arr[num]); //输出英文月份
}
}
有问题请追问 满意请采纳
展开全部
算法:查表法、
内置一个二维字符数组,12个元素即可。
输入1~12时,打印对应的字符数组,否则提示有误。
内置一个二维字符数组,12个元素即可。
输入1~12时,打印对应的字符数组,否则提示有误。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2011-11-10
展开全部
#include<stdio.h>
int main()
{
int n;
scanf("%d",&n);
switch(n)
{
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;
default:
printf("input error!");
}
printf("\n");
return 0;
}
int main()
{
int n;
scanf("%d",&n);
switch(n)
{
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;
default:
printf("input error!");
}
printf("\n");
return 0;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
# include<stdio.h>
main()
{
int month;
char a[12][10]={"January","Febuary","March","April","May","June","July","August","September","October","November","December"};
printf("请输入月份:\n");
scanf("%d",&month);
printf("%s",a[month-1]);
}
main()
{
int month;
char a[12][10]={"January","Febuary","March","April","May","June","July","August","September","October","November","December"};
printf("请输入月份:\n");
scanf("%d",&month);
printf("%s",a[month-1]);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询