返回列表 發帖

while 迴圈

利用while迴圈, 垂直列出 1~20.
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int i=1;  //初始值
  7.     while(i<=20)    //持續運作的條件
  8.     {
  9.         cout<<i<<endl;
  10.         i++;   
  11.     }
  12.     system("pause");
  13.     return 0;   
  14. }
複製代碼

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int i = 1;
  7.     while(i<=20)
  8.     {
  9.         cout<<i<<endl;
  10.         i+=1;
  11.     }
  12.    
  13.    
  14.    
  15.     system("pause");
  16.     return 0;
  17. }
複製代碼

TOP

本帖最後由 王建葦 於 2019-5-25 11:04 編輯
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.    int x=0;
  7.    
  8.       while(x<=20)
  9.       {
  10.         cout<<x<<endl;
  11.         x++;           

  12.    }
  13.    system("pause");
  14.    return 0;

  15. }
複製代碼

TOP

  1. #include<cstdlib>
  2. #include<iostream>
  3. using namespace std;
  4. int main()
  5. {
  6.     int a=1;
  7.     while(a<=20)
  8.     {
  9.        cout<<a<<endl;
  10.        a++;
  11.     }
  12.     system("pause");
  13.     return 0;
  14. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.    int a=1;
  7.    while(a<=20)
  8.    {
  9.    cout<<a<<endl;
  10.    a++;            
  11.    }
  12.     system("pause");
  13.     return 0;   
  14. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int a=1;
  7.     while(a<=20)
  8.     {
  9.         cout<<a<<endl;
  10.         a++;
  11.     }
  12.     system("pause");
  13.     return 0;
  14. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6. int x=1
  7. while(x<=20)
  8. {
  9.             
  10.   cout<<x<<endl;
  11.   x++         
  12.             }




  13. }


  14. system("pause");
  15. return 0;
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int i=1;
  7.     while(i<=20)
  8.     {
  9.        cout<<i<<endl;
  10.        i++;         
  11.                 }

  12.     system("pause");
  13.     return 0;
  14. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int i=1;

  7.     while(i<=20)
  8.     {
  9.        cout<<i<<endl;         
  10.        i++;         
  11.     }
  12.   system("pause");
  13.   return 0;   
  14. }
複製代碼

TOP

返回列表