回覆列表
  • 1 # 使用者7899743719261

    #include <stdio.h>#include <string.h>int main() { char digit[10][3] = {"零", "一", "二", "三", "四", "五", "六", "七", "八", "九"}; char unit[4][3] = {"十", "百", "千", "萬"}; char minusculeStr[6]; //儲存整數轉換後的字串 int temp, strLength, i; int minuscule; printf("請輸入一個整數(一萬以內): "); scanf("%d", &minuscule); memset(minusculeStr, 0, 6); temp = minuscule; for (i = 0; temp; temp /= 10, i++) { minusculeStr[i] = temp % 10 + 48; //轉換整數每一位為對應字元存入字元陣列 } strLength = strlen(minusculeStr); for (i = strLength; i > 0; i--) //列印整數的大寫 if(minusculeStr[i - 1] != "0") printf("%s%s", digit[minusculeStr[i - 1] - 48], unit[i - 2]); else if(minusculeStr[i - 2] == "0" || i == 1) ; //Do nothing else printf("%s", digit[minusculeStr[i - 1] - 48]); //最佳化輸出格式,更接近書面語 putchar("\n"); return 0;}

  • 中秋節和大豐收的關聯?
  • 華為手機搜不到wifi熱點怎麼辦?