题目:
编写一个程序,输入月份号,输出该月的中文名和英文名。
例如,输入“3”,则输出三月份,输出March,要求用指针数组处理。
#include<iostream> #include<string> using namespace std; int main(){ int a[12]={1,2,3,4,5,6,7,8,9,10,11,12}; char * b[2][12]={ {"一月份","二月份","三月份","四月份","五月份","六月份","七月份","八月份", "九月份","十月份","十一月份","十二月份"}, {"January","February","March","April","May","June","July","August","September", "October","November","December"} }; cout<<"请输入一个表示月份的数字(1~12):"; int n; cin>>n; cout<<" "<<endl; for(int i=0;i<12;i++){ if(a[i]==n){ cout<<b[0][i]<<" "<<endl; cout<<b[1][i]<<endl; } } cout<<" "<<endl; return 0; }
运行界面: