返回列表 發帖

巢狀迴圈 (二)

本帖最後由 tonyh 於 2012-8-9 09:34 編輯

利用巢狀回圈, 在螢幕上將*號排列成一正立三角形如下:

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

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

TOP

  1. #include <iostream>

  2. using namespace std ;

  3. int main()
  4. {
  5.     for(int i=1 ; i<=50 ; i++)
  6.     {
  7.       for(int j=1; j<=i ;j++)
  8.       {
  9.            cout<<"*";
  10.       }
  11.       cout<<endl;
  12.          
  13.     }
  14. system("pause");
  15. return 0;
  16. }
複製代碼

TOP

  1. #include <iostream>

  2. using namespace std ;

  3. int main()
  4. {
  5.     for(int i=1 ;i<=5 ;i++)
  6.     {
  7.         for(int j=1 ;j<=i ;j++)
  8.         {
  9.          cout<<"*";        
  10.         }
  11.         cout<<endl;      
  12.     }
  13.      
  14. system("pause");
  15. return 0;
  16. }
複製代碼

TOP

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

TOP

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

TOP

  1. #include<iostream>
  2. using namespace std;
  3. int main()
  4. {

  5.      for(int i=1; i<=5; i++)
  6.      {
  7.              for(int j=1; j<=i;j++)
  8.              {
  9.                   cout<<"*";
  10.              }
  11.              cout<<endl;
  12.       
  13.      }
  14.           cout<<endl;
  15.      system("pause");
  16.      return 0;   
  17. }
複製代碼

TOP

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

TOP

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

TOP

返回列表