Try   HackMD

題目清單

Part 1. 練習題解答

1. Quiz 1: Hello World!

#include <iostream> using namespace std; int main(){ cout << "Hello world!"; return 0; }

2. Quiz 2: cout 練習

#include <iostream> using namespace std; int main(){ cout << "I'm from"<< endl; cout << "Team 0!"; return 0; }

3. Quiz 3: 輸入三角形邊長

#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: 計算金字塔的秘密數值

#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: 這是一座直角金字塔嗎?

#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: 這是哪種神秘金字塔?

#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: 金字塔數據庫

#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; }