建立一个C++控制台程序,程序功能实现输入月份号,输出该月的英文月名。要求使用指针数组。

如题所述

vc6.0验证过,用到了指针数组。p[0]指向空串。
#include <iostream.h>
void main ()
{
int mon=0;
char *p[13]={"","January","February","March","April","May","June","July","August","September","October","November","December"};
cout<<"输入月份号:"<<endl;
cin>>mon;
cout<<p[mon]<<endl;
}
温馨提示:内容为网友见解,仅供参考
第1个回答  2010-10-28
//直接写的,你看看
#include"iostream.h"
void main()
{
char*month[13]={"0","January","February","March", "April" , "May", "June", "July","August" ,"September" ,
"October" ,"November" ,"December"
} ;

int inNum;
cin>>inNum;
while(inNum>0&&inNum<13)//只要输入不在1-12范围内就结束
{
cout<<month[inNum]<<endl;
cin>>inNum;
}
}
相似回答