--- tags: DICE C --- 17-9 相反數絕對值 === > [name=CHAWTeam] --- 目錄:[DICE C語言程式破解](/@CHAWTeam/DiceC) --- 題目 -- ```! 請撰寫一程式,輸入一個整數,印出其相反數與絕對值,格式如輸出範例所示。 程式重複輸入,直到輸入0才停止。 輸入範例: 6 7 8 -6 -7 -8 0 輸出範例: 6的相反數-6 6的絕對值6 7的相反數-7 7的絕對值7 8的相反數-8 8的絕對值8 -6的相反數6 -6的絕對值6 -7的相反數7 -7的絕對值7 -8的相反數8 -8的絕對值8 ``` 程式碼 -- ```c= #include <stdio.h> #include <stdlib.h> int main() { int x; scanf("%d", &x); while (x != 0) { printf("%d的相反數%d\n", x, x * -1); printf("%d的絕對值%d\n", x, abs(x)); scanf("%d", &x); } return 0; } ``` 執行 -- ### 輸入 ```! 6 7 8 -6 -7 -8 0 ``` ### 輸出 ```! 6的相反數-6 6的絕對值6 7的相反數-7 7的絕對值7 8的相反數-8 8的絕對值8 -6的相反數6 -6的絕對值6 -7的相反數7 -7的絕對值7 -8的相反數8 -8的絕對值8 ``` --- [查看我們在HackMD上的所有筆記](/@CHAWTeam) 目錄:[DICE C語言程式破解](/@CHAWTeam/DiceC) --- {%hackmd Iiu5mOixR7yWkPHKCkabBg %} <iframe class="LikeCoin" height="235" src="https://button.like.co/in/embed/chawteam/button?referrer=https://hackmd.io/@CHAWTeam/DiceC-17-9" width="100%"></iframe> --- {%hackmd i1nMRrZcTFmTvoF897K9zg %}
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up