编一程序,输入月份号,输出该月的英文月名。例如,输人3,则输出"March" ,要求用指针数组处理
编一程序,输入月份号,输出该月的英文月名。例如,输人3,则输出"March" ,要求用指针数组处理
解题思路: 首先定义字符串指针数字,数组中每一个元素都存放一个字符串指针,每个指针指向不同字符串的位置。则输入月份数字后,根据下标获取对应月份字符串的地址即可
答案:
#include<stdio.h>
int main()
{
int month;
char* Month[12] = { "January","February","March","April","May","June",
"July","August","September","October","November","December" };
while (1) {
printf("Please enter the month: ");
scanf_s("%d", &month);
if (month < 1 && month>12) {
printf("Input error, Month should be greater than 0 and less than 12
");
}
printf("%s
", Month[month - 1]);
}
return 0;
}
编一程序,输入月份号,输出该月的英文月名。例如,输人3,则输出"March" ,要求用指针数组处理
原文:https://www.cnblogs.com/vs2019/p/13630974.html