# 第九周 一維陣列 寫程式時,時常遇到大量同類別的變數,這時候就可以利用陣列來宣告變數 ## 練習 說明:多名學生分別輸入姓名、國文、英文、數學成績,以陣列表示並計算其學生的平均成績 ```=cpp #include <bits/stdc++.h> using namespace std; int main() { int score[3]; float avg = 0; cout << "輸入第1位學生的成績:"; cin >> score[0]; cout << "輸入第2位學生的成績:"; cin >> score[1]; cout << "輸入第3位學生的成績:"; cin >> score[2]; avg += score[0] + score[1] + score[2]; avg /= 3.0f; cout << "平均成績=" << avg << endl; system("pause"); } ```
×
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