编写一个程序,输入月份号,输出该月份号的英文名称

问题详情:编写一个程序,输入月份号,输出该月份号的英文名称。例如输入8,测输出“August”,要求用指针数组处理。

我的代码:

#include
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语言)