Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2509533
  • 博文数量: 308
  • 博客积分: 5547
  • 博客等级: 大校
  • 技术积分: 3782
  • 用 户 组: 普通用户
  • 注册时间: 2009-11-24 09:47
个人简介

hello world.

文章分类

全部博文(308)

分类: C/C++

2010-08-24 11:26:46

    编写一程序,打入月份号,输出该月的英文月名。例如,输入“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;
}


阅读(1269) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~