让用户输入一个数字(0-9),然后输出对应的大写汉字。
注:零 壹 贰 叁 肆 伍 陆 柒 捌 玖
例如,用户输入3, 输出“叁”
#include
#include
#include <Windows.h>
using namespace std;
//零 壹 贰 叁 肆 伍 陆 柒 捌 玖
int main(void) {
int num;
string ret;
cout << "请输入一个数字[0-9]: ";
cin >> num;
switch (num) {
case 0:
cout << "零";
break;
case 1:
cout << "壹";
break;
case 2:
cout << "贰";
break;
case 3:
cout << "叁";
break;
case 4:
cout << "肆";
break;
case 5:
cout << "伍";
break;
case 6:
cout << "陆";
break;
case 7:
cout << "柒";
break;
case 8:
cout << "捌";
break;
case 9:
cout << "玖";
break;
default:
break;
}
cout << endl;
system("pause");
return 0;
}
或者
#include
#include
#include <Windows.h>
using namespace std;
int main(void) {
int num;
string ret[10] = {“零”, “壹”, “贰”, “叁”, “肆”, “伍”, “陆”, “柒”, “捌”, “玖”};
cout << "请输入一个数字[0-9]: ";
cin >> num;
if (num >=0 && num <=9) {
cout << ret[num] << endl;
}
system("pause");
return 0;
}