--- tags: 程式範例,python,cpp --- # 程式範例解答 # C++ ## 輸出入 ### 1.1 (Display two messages) Write a program that displays **Introduction to Computers** and **Welcome to Object-Oriented Programming**. ```cpp= // P46 practice quiz 1.1 #include <iostream> using namespace std; int main(){ cout<<"Introduction to Computers."<<endl; cout<<"Welcome to Object-Oreiented Programming."<<endl; return 0; } ``` ### 1.2 (Display five messages) Write a program that displays **Welcome to C++** five times. ```cpp= // P46 practice quiz 1.2 寫法一 #include <iostream> using namespace std; int main(){ cout<<"Welcome to C++"<<endl; cout<<"Welcome to C++"<<endl; cout<<"Welcome to C++"<<endl; cout<<"Welcome to C++"<<endl; cout<<"Welcome to C++"<<endl; return 0; } ``` ```cpp= // P46 practice quiz 寫法二 #include <iostream> using namespace std; int main(){ for(int i=0;i<5;i++){ cout<<"Welcome to C++"<<endl; } return 0; } ``` ### 1.3 (Display a pattern) Write a program that displays the following pattern. ```cpp= // P46 practice quiz #include <iostream> using namespace std; int main(){ return 0; } ``` ### 1.4 (Print a table) Write a program that displays the following table: ```cpp= // P46 practice quiz #include <iostream> using namespace std; int main(){ return 0; } ``` ### 1.5 ```cpp= // P46 practice quiz #include <iostream> using namespace std; int main(){ return 0; } ``` ### 1.6 ```cpp= // P46 practice quiz #include <iostream> using namespace std; int main(){ return 0; } ``` ### 1.7 ```cpp= // P46 practice quiz #include <iostream> using namespace std; int main(){ return 0; } ``` ### 1.8 ```cpp= // P46 practice quiz #include <iostream> using namespace std; int main(){ return 0; } ``` ### 1.9 ```cpp= // P46 practice quiz #include <iostream> using namespace std; int main(){ return 0; } ``` ## 變數使用 ## 運算子 ## 判斷式 ## while迴圈 ## for迴圈 # Python ## 輸出入 ## 變數使用 ## 運算子 ## 判斷式 ## while迴圈 ## for迴圈