返回列表 發帖

[隨堂測驗] 函式的建立與執行 (二)

試以自訂函式的方式, 設計一個專門顯示 "歡迎光臨" 的程式, 只需輸入次數, 即可重複顯示.
執行畫面如下:



本帖隱藏的內容需要回復才可以瀏覽

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;

  4. //hello函式
  5. void hello(){
  6.         cout<<"這是hello函式"<<endl;
  7. }


  8. //welcome函式
  9. void welcome(int x){
  10.         for(int i=1;i<=x;i++){
  11.                 cout<<"歡迎光臨"<<endl;
  12.         }
  13. }
  14. //宣告變數->變數型態 變數名字
  15. //int a
  16. //宣告函式->回傳型態 函式名字()
  17. //int myPlus
  18. //沒有回傳值時 void


  19. //主函式
  20. int main(){
  21.         int a; //次數
  22.         cout<<"請輸入次數:";
  23.         cin>>a;
  24.        
  25.         welcome(a);
  26.        
  27.         system("pause");
  28.         return 0;
  29. }
複製代碼

TOP

返回列表