问题详情:编写一个程序,输入月份号,输出该月份号的英文名称。例如输入8,测输出“August”,要求用指针数组处理。
我的代码:
#include<stdio.h>
int main()
{
//定义一个指针数组存储月份名称
char *months[12]={"January","February","March","April","May","June","July","August","September","October","December"};
//声明用来存储月份号的变量
int number;
printf("Please enter the month:\n");
scanf("%d",&number);
//实际在数组中的次序比月份号少1
number--;
printf("The month's name is:");
//输出月份名称
printf("%s",*(months+number));
return 0;
}
示例输出结果(其中5是输入值):
Please enter the month:
5
The month's name is:May
本文介绍了一个使用C语言指针数组实现输入月份号并输出对应英文月份名称的程序示例。通过定义指针数组存储月份名称,并利用用户输入的月份号减一作为数组下标来获取对应的月份名称。
535

被折叠的 条评论
为什么被折叠?



