回覆列表
  • 1 # 筱拾貳

    可以用swich的case 語句結合來寫,而我認為數的判定方式有多種,在這裡,對於整數部分我們可以用將數值“三位為一組”來進行分!

    如:678為第一組,前面加上 thousand

    345為第二組,前面加上 million

    依次為 billion

    對於每組中的三個數分別含 百位 十位 個位

    而小數點後面的則可以不用分位數,直接接對應的數!

    下面是類似程式:

    #include<stdio.h>

    void main()

    {

    char *Eng1[20]={"zero","one","two","three","four","five","six","seven",

    "eight","nine","ten","eleven","twelve","thirteen","fourteen","fifteen",

    "sixteen","seventeen","eighteen","nineteen"};

    char *Eng2[8]={"twenty","thirty","fourty","fifty","sixty","seventy","eighty","ninety"};

    int num;

    printf("請輸入數字: ");

    scanf("%d",&num);

    printf("對應的英文為: ");

    if(num>=0&&num<=19)

    printf("%s\n",Eng1[num]);

    else if(num<100)

    {

    int s,y;

    s=num/10;

    y=num%10;

    printf("%s %s\n",Eng2[s-2],Eng1[y]);

    }

    else if(num<1000)

    {

    int b,s,y;

    b=num/100;

    y=num%100;

    if(y>9)

    {

    s=(num%100)/10;

    y=(num%100)%10;

    if(y==0)

    printf("%s hundred and %s\n",Eng1[b],Eng2[s-2]);

    else

    printf("%s hundred and %s %s\n",Eng1[b],Eng2[s-2],Eng1[y]);

    }

    else

    printf("%s hundred and %s\n",Eng1[b],Eng1[y]);

    }

    }

  • 中秋節和大豐收的關聯?
  • 為什麼林正英總提洪金寶啊?