--- tags: DICE C --- 19-8 阿姆斯壯數-2 === > [name=CHAWTeam] 目錄:[DICE C語言程式破解](/@CHAWTeam/DiceC) 題目 --- ```! 所謂阿姆斯壯數是指一個三位數的整數,其各位數字之立方和等於該數本身。 例如:153是一個阿姆斯壯數,因為153=1^3+5^3+3^3。 請撰寫一程式,輸入a、b兩整數, 判斷a到b之間是否有阿姆斯壯數,分別印出「有」或「無」。 程式重複輸入,直到輸入的兩整數皆為0才停止。 輸入範例: 100 300 500 900 400 800 600 500 0 0 輸出範例: 有 無 有 無 ``` 程式碼 --- ```c= #include <stdio.h> #include <math.h> int main() { int a, b, t, armstrong; scanf("%d %d", &a, &b); for (int judge = 0; a != 0 && b != 0; judge = 0) { if (a > b) { t = a; a = b; b = t; } for (int i = a; i <= b; i++) { t = i; while (t != 0) { armstrong += pow(t % 10, 3); t /= 10; } if (armstrong == i) judge = 1; armstrong = 0; } if (judge == 1) printf("有\n"); else printf("無\n"); scanf("%d %d", &a, &b); } return 0; } ``` 執行 --- ### 輸入 ```! 100 300 500 900 400 800 600 500 0 0 ``` ### 輸出 ```! 有 無 有 無 ``` --- [查看我們在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-19-8" width="100%"></iframe> --- {%hackmd i1nMRrZcTFmTvoF897K9zg %}
×
Sign in
Email
Password
Forgot password
or
Sign in via Google
Sign in via Facebook
Sign in via X(Twitter)
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
Continue with a different method
New to HackMD?
Sign up
By signing in, you agree to our
terms of service
.