Board logo

標題: while 迴圈 [打印本頁]

作者: 周政輝    時間: 2017-5-20 09:01     標題: while 迴圈

利用while迴圈, 垂直列出 1~10.
  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. }
複製代碼

作者: 高品溫    時間: 2017-5-20 09:03

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

作者: 莊旻叡    時間: 2017-5-20 09:06

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

作者: 高睿辰    時間: 2017-5-26 18:02

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





歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/) Powered by Discuz! 7.2