编写一个程序,输入月份号,输出该月的中文名和英文名。
题目:
编写一个程序,输入月份号,输出该月的中文名和英文名。
例如,输入“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<<"\n"<<endl; for(int i=0;i<12;i++){ if(a[i]==n){ cout<<b[0][i]<<"\n\n"<<endl; cout<<b[1][i]<<endl; } } cout<<"\n"<<endl; return 0; }
运行界面:
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步