Last active
December 9, 2017 03:29
-
-
Save goodjack/a3c0401764e90855398ca6b1bba2a902 to your computer and use it in GitHub Desktop.
20171123 使用陣列參考解答 & 20171207 多重 for 迴圈時鐘範例
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main() | |
{ | |
int students, total = 0; | |
cout << "班級人數:"; | |
cin >> students; | |
int score[students]; | |
for (int i = 0; i < students; i++) { | |
cout << i + 1 << " 號同學的成績:"; | |
cin >> score[i]; | |
} | |
for (int i = 0; i < students; i++) { | |
total += score[i]; | |
} | |
cout << "全班總分是:" << total; | |
cout << "全班平均是:" << total/students; | |
// ===== 查詢學生成績 ===== // | |
int studentNo; | |
while (true) { | |
cout << "查詢座號:"; | |
cin >> studentNo; | |
// 超過座號範圍就終止程式 | |
if (studentNo < 1 || studentNo > students) { // 想想看為什麼 students 不用 +1? | |
break; | |
} | |
cout << i + 1 << "號同學的成績是 " << score[studentNo] << "分" << endl; | |
} | |
cout << "程式結束 掰掰"; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main() | |
{ | |
for (int hour = 0; hour <= 23; hour++) { | |
for (int minute = 0; minute <= 59; minute++) { | |
for (int second = 0; second <= 59; second++) { | |
// 未達兩位數時補 0 | |
if (hour < 10) { | |
cout << "0"; | |
} | |
cout << hour << ":"; | |
if (minute < 10) { | |
cout << "0"; | |
} | |
cout << minute << ":"; | |
if (second < 10) { | |
cout << "0"; | |
} | |
cout << second << endl; // 最後顯示完秒數後換行 | |
} | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment