C++实例 将数字转换为汉字
#include <iostream> #include <string> using namespace std; void changeword(int number); int main(int argc, char* argv) { char number[255]; char* p; cout<<"please input a number!"<<endl; gets(number); //puts(number); p = number; for(;*p!='\0';p++) { //cout << "abc" << (int)*p-48 << endl; changeword((int)*p-48); } return 0; } void changeword(int number) { switch(number) { case 0: cout<<"零"<<endl; break; case 1: cout<<"一"<<endl; break; case 2: cout<<"二"<<endl; break; case 3: cout<<"三"<<endl; break; case 4: cout<<"四"<<endl; break; case 5: cout<<"五"<<endl; break; case 6: cout<<"六"<<endl; break; case 7: cout<<"七"<<endl; break; case 8: cout<<"八"<<endl; break; case 9: cout<<"九"<<endl; break; } }
学习笔记转摘于:
丝酷网 http://www.pythonschool.com/