返回列表 發帖

小星星 3

本帖最後由 tonyh 於 2014-11-8 10:58 編輯

利用巢狀迴圈, 試做一個長為10顆*, 高為4顆*, 之平行四邊形, 排列如下圖:

  1. #include <iostream>
  2. #include <cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.   for(_____________)
  7.   {
  8.        for(_____________)
  9.        {
  10.             cout<<" ";   
  11.        }
  12.        for(_____________)
  13.        {
  14.             cout<<"*";   
  15.        }
  16.        cout<<endl;         
  17.   }      
  18.   system ("pause");
  19.   return 0;   
  20. }
複製代碼
  1. #include <iostream>
  2. #include <cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.   for(int i=1; i<=4; i++)
  7.   {
  8.        for(int j=1; j<=4-i; j++)
  9.        {
  10.             cout<<" ";   
  11.        }
  12.        for(int k=1; k<=10; k++)
  13.        {
  14.             cout<<"*";   
  15.        }
  16.        cout<<endl;         
  17.   }      
  18.   system ("pause");
  19.   return 0;   
  20. }
複製代碼
附件: 您需要登錄才可以下載或查看附件。沒有帳號?註冊

  1. #include<iostream>
  2. using namespace std;
  3. int main()
  4. {
  5.     int i;
  6.     int j;
  7.     for(i=0;i<4;i++)
  8.     {
  9.           for(j=4;j>i;j--)
  10.           {
  11.               cout<<" ";
  12.           }
  13.           for(j=0;j<10;j++)
  14.           {
  15.               if(j==0)
  16.                   cout<<"◢"; //A2A8
  17.               else if(j==9)
  18.                   cout<<"◤"; //A2AB
  19.               else
  20.                   cout<<"▉"; //A270  
  21.           }
  22.     cout<<endl;      
  23.     }
  24.     system("pause");
  25.     return 0;
  26. }
複製代碼

TOP

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

TOP

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

TOP

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

TOP

本帖最後由 梁和雋 於 2014-10-25 11:48 編輯
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     for(int i=1; i<=4; i++)
  7.     {
  8.         for(int j=1; j<=4-i; j++)
  9.         {
  10.              cout<<" ";            
  11.         }
  12.          for(int a=10; a>=1; a-- )
  13.        {
  14.             cout<<"*";   
  15.        }
  16.         cout<<endl;   
  17.     }
  18.     system ("pause");
  19.     return 0;
  20. }
複製代碼
http://fs-old.mis.kuas.edu.tw/~s1102137106/music/

TOP

返回列表