编写一程序,打入月份号,输出该月的英文月名。例如,输入“3”,则输出"March".要求用指针数组处理。
我们可以使用指针数组中的每一个单元指向一个月份,然后使用指针的指针去查找这个单元,找到后,将指针的指针停留在此位置,然后输出即可。代码如下:
#include <stdio.h>
int main(int argc, char *argv[]) { char *months[12] = {"January","February","Marcy","April","May","June","July","August","September","October","November","December"}; char **p; p = months; int i_month,i = 0; printf("please input months number(1 - 12):"); scanf("%d",&i_month); while (i_month > 12 || i_month < 1) { printf("you input number is error,please reinput(1 - 12):"); scanf("%d",&i_month); } while (++i != i_month) { p++; } printf("the %d month english is %s.\n",i_month,*p); system("pause"); return 0; }
|
阅读(1293) | 评论(0) | 转发(0) |