返回列表 發帖

while 迴圈

利用while迴圈, 垂直列出 1~20.

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

  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.     cout<< i  ;
  9.     i++
  10. }
  11.     for(int i=1 ; i<=20;i++){cout<<i;}
  12.     system("pause");
  13.     return 0;  
複製代碼

TOP

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

TOP

本帖最後由 張翼安 於 2015-12-19 11:46 編輯
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.      int i=1;
  7.      while(i<=20){
  8.              cout<<i<<endl;
  9.              i++;
  10.     }
  11.     system("pause");
  12.     return 0;
  13. }
複製代碼

TOP

返回列表