--- tags: DICE C --- 15-5 班級均分-完成 === > [name=CHAWTeam] --- 目錄:[DICE C語言程式破解](https://hackmd.io/@CHAWTeam/DiceC) --- 題目 -- ```! 寫一個程式,它可以處理任何筆數的成績,來處理全班分數。 最後一個工作: 重複輸入,直到輸入「-1」,才停止。 請輸出「全班平均分數」,輸出到小數第六位。 輸入範例: 75 75 75 88 70 64 83 89 -1 輸出範例: 77.375000 ``` 程式碼 -- ```c= #include <stdio.h> int main() { int x, sum = 0; float n = 0; scanf("%d", &x); while (x != -1) { sum += x; n++; scanf("%d", &x); } printf("%f\n", sum / n); return 0; } ``` 執行 -- ### 輸入 ```! 75 75 75 88 70 64 83 89 -1 ``` ### 輸出 ```! 77.375000 ``` --- [查看我們在HackMD上的所有筆記](https://hackmd.io/@CHAWTeam) 目錄:[DICE C語言程式破解](https://hackmd.io/@CHAWTeam/DiceC) --- {%hackmd Iiu5mOixR7yWkPHKCkabBg %} <iframe class="LikeCoin" height="235" src="https://button.like.co/in/embed/chawteam/button?referrer=https://hackmd.io/@CHAWTeam/DiceC-15-5" 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