## 題目清單 ## Part 1. 練習題解答 ### 1. Quiz 1: Hello World! ```cpp= #include <iostream> using namespace std; int main(){ cout << "Hello world!"; return 0; } ``` ### 2. Quiz 2: cout 練習 ```cpp= #include <iostream> using namespace std; int main(){ cout << "I'm from"<< endl; cout << "Team 0!"; return 0; } ``` ### 3. Quiz 3: 輸入三角形邊長 ```cpp= #include <iostream> using namespace std; int main(){ int a, b, c; cin >> a >> b >> c; cout << "Side 1: " << a << '\n'; cout << "Side 2: " << b << '\n'; cout << "Side 3: " << c << '\n'; return 0; } ``` ### 4. Quiz 4: 計算金字塔的秘密數值 ```cpp= #include <iostream> using namespace std; int main(){ double a, b, c; cin >> a >> b >> c; cout << (a + b + c) << '\n'; cout << (a * b * c) << '\n'; cout << (a + b + c) / 3 << '\n'; return 0; } ``` ### 5. Quiz 5: 這是一座直角金字塔嗎? ```cpp= #include <iostream> using namespace std; int main(){ int a, b, c; cin >> a >> b >> c; if(a * a + b * b == c * c){ cout << "Right triangle pyramid."; } else{ cout << "Not a right triangle pyramid."; } return 0; } ``` ### 6. Quiz 6: 這是哪種神秘金字塔? ```cpp= #include <iostream> using namespace std; int main(){ int a, b, c; cin >> a >> b >> c; if(a * a + b * b == c * c){ cout << "Right triangle pyramid."; } else if(a * a + b * b > c * c){ cout << "Acute triangle pyramid."; } else{ cout << "Obtuse triangle pyramid."; } return 0; } ``` ### 7. Quiz 7: 金字塔數據庫 ```cpp= #include <iostream> using namespace std; int main(){ int a[2][3] = {0}; cin >> a[0][0] >> a[0][1] >> a[0][2]; cin >> a[1][0] >> a[1][1] >> a[1][2]; cout << "Pyramid 1: " << (a[0][0] + a[0][1] + a[0][2]) << '\n'; cout << "Pyramid 2: " << (a[1][0] + a[1][1] + a[1][2]) << '\n'; return 0; } ``` ### 8. Quiz 8: 連加 #### while ```cpp= #include <iostream> using namespace std; int main(){ int sum = 0; int a = 1; while(a <= 1000){ sum += a; a++; } cout << "1+2+3+...+1000 = " << sum; return 0; } ``` #### for ```cpp= #include <iostream> using namespace std; int main(){ int sum = 0; for(int i = 1; i <= 1000; i++){ sum += i; } cout << "1+2+3+...+1000 = " << sum; return 0; } ``` ### 9. Quiz 9: 輸出長方形 ```cpp= #include <iostream> using namespace std; int main(){ int n, m; cout << "Enter m = "; cin >> m; cout << "Enter n = "; cin >> n; for(int i = 0; i < m; i++){ for(int j = 0; j < n; j++){ cout << '*'; } cout << endl; } return 0; } ```
×
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