--- tags: DICE C --- 12-6 計算機 === > [name=CHAWTeam] --- 目錄:[DICE C語言程式破解](https://hackmd.io/@CHAWTeam/DiceC) --- 題目 --- ```! 輸入一個整數,再輸入運算子(+-*/%^#),再輸入另一個整數,輸出運算結果(若除法無法整除則只取商數)。 令%為取餘數,^為次方,#為開根號。數字跟符號中間都有隔開。 輸入範例1: 3 + 3 輸出範例1: 6 輸入範例2: 4 / 5 輸出範例2: 0 輸入範例3: 6 ^ 3 輸出範例3: 216 輸入範例4: 125 # 3 輸出範例4: 5 ``` 程式碼 --- ```c= #include <stdio.h> #include <math.h> int main() { int a, b; char c; scanf("%d %c %d", &a, &c, &b); if (c == '+') printf("%d\n", a + b); if (c == '-') printf("%d\n", a - b); if (c == '*') printf("%d\n", a * b); if (c == '/') printf("%d\n", a / b); if (c == '%') printf("%d\n", a % b); if (c == '^') printf("%.f\n", pow(a, b)); if (c == '#') printf("%d\n", pow(a, 1.0 / b)); return 0; } ``` :::success `#include <math.h>` 為載入數學函示庫,其中在本題會用到**次方 `pow()`** 。 ::: 執行 --- ```! 3 + 3 6 ``` ```! 4 / 5 0 ``` ```! 6 ^ 3 216 ``` ```! 125 # 3 5 ``` --- [查看我們在HackMD上的所有筆記](https://hackmd.io/@CHAWTeam) 目錄:[DICE C語言程式破解](https://hackmd.io/@CHAWTeam/DiceC) 上一篇:[12-5 運算列表](https://hackmd.io/@CHAWTeam/DiceC-12-5) 下一篇:[13-1 HaHaHa!笑他10次](https://hackmd.io/@CHAWTeam/DiceC-13-1) --- {%hackmd Iiu5mOixR7yWkPHKCkabBg %} <iframe class="LikeCoin" height="235" src="https://button.like.co/in/embed/chawteam/button?referrer=https://hackmd.io/@CHAWTeam/DiceC-12-6" width="100%"></iframe> --- {%hackmd i1nMRrZcTFmTvoF897K9zg %}