返回列表 發帖

[隨堂測驗] 小星星 4

利用巢狀迴圈, 試做一個長為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.     for(int i=1;i<=4;i++)
  6.         {
  7.         for(int j=0;j<=i-2;j++)
  8.         {
  9.             cout<<" ";
  10.         }
  11.         for(int k=1;k<=10;k++)
  12.         {
  13.             cout<<"*";
  14.         }
  15.             cout<<endl;
  16.     }
  17.     system ("pause");
  18.     return 0;
  19. }
複製代碼

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<=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. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     for(int i=0; i<=3; i++)
  7.     {
  8.         for(int j=1; j<=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. }
複製代碼

TOP

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

  6. for(int i=0;i<=3;i++){
  7.         for(int j=1; j<=i; j++){
  8.             cout<<" ";
  9.         }
  10.         for(int k=1; k<=10; k++){
  11.             cout<<"*";

  12.         }
  13. cout<<endl;
  14. }

  15. system("pause");
  16. return 0;
  17. }
複製代碼

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=2 ; j<=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. }
複製代碼

TOP

本帖最後由 高湘庭 於 2024-6-22 14:27 編輯
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main(){
  5. for(int i=1;i<=4;i++)
  6. {
  7.     for(int j=1;j=<i-1;j++)
  8.     {
  9.         cout<<" ";
  10.     }
  11.     for(int k=1;k<=10;k++)
  12.     {cout<<"*";}
  13.     cout<<endl;
  14. }

  15. system("pause");
  16. return 0;

  17. }
複製代碼

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<=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. }
複製代碼

TOP

返回列表