English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
所有分類

比如說輸入1234 輸出就會為 壹仟兩佰參拾四
請問要怎麼寫呢?

2006-11-25 13:52:09 · 2 個解答 · 發問者 polk 1 in 電腦與網際網路 程式設計

2 個解答

#include
void main()
{
int input, //User輸入值
temp,
count[10];
int counter=0; //紀錄有幾位數
int temp2=0;
char word[5][4] = {"零","拾","佰","仟","萬"};//一個字元是1byte,國字是4byte
char word2[10][4] = {"\0","一","兩","三","四","五","六","七","八","九"};
cout<<"Please Input a NUM===> ";
cin>>input;
cout<<"input="< temp=input;
cout<<"反輸出";
aaa:

if (temp!=0) //(temp>0 || temp<0)
{
count[temp2]=temp % 10 ;//temp2初始為0
temp=temp / 10;
cout< counter++;
temp2++;
if (temp==0)
{
cout< goto bbb;
}
else
goto aaa;
}
cout<
bbb:
//counter代表有幾位數了
int temp3=0;
int temp4=counter-1; //因為位數跟陣列剛好差一位
cout<<"位數="< for(int i=counter-1;i>=0;i--)
{

temp3=count[temp4]; //記錄位數

if(temp3!=0)
{ //因為若輸入12345 a[0]=5 , a[1]=4 , a[2]=3....
cout< if(i!=0)
cout << word[i];
}
else
{
if(count[temp4-1]!=0 && i!=0 ) //避免造成
cout << "零";
}
temp4--;
}
}

2006-11-30 11:45:02 補充:
裡面的一二三四五六七八九請自行改囉改成壹貳參肆伍陸柒捌玖

2006-11-30 06:41:45 · answer #1 · answered by ALLEN CHEN 2 · 0 0

下面為示範程式碼,一個中文字佔兩個位元組,由兩個字元組成,當成一個字串列印到螢幕上。//Power by Microsoft Visual Studio 2005//可以使用 Dev-C++ 編譯此程式#include#include#includeint main(int argc, char *argv[]){ //=====START=====// char word[3],string[]="拾佰仟萬"; int i; for(i=0;i<(int)strlen(string)/2;i++){  *(word+0)=string[2*i];  *(word+1)=string[2*i+1];  *(word+2)='\0';  printf("%s\n",word); } //=====END=====// system("PAUSE"); return 0;}

2006-11-25 15:20:34 · answer #2 · answered by Big_John-tw 7 · 0 0

fedest.com, questions and answers