返回列表 發帖
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4.        

  5. void say_hello()
  6. {
  7.         cout<<"*======================*"<<endl;
  8.         cout<<"*歡迎使用璽安小星星軟體*"<<endl;
  9.         cout<<"*======================*"<<endl;
  10. }
  11. void triangle1()
  12. {
  13.         for(int i = 1 ; i <=5 ; i++)
  14.         {
  15.                 for(int j = 1 ; j <=i ; j++)
  16.        
  17.                 {
  18.                         cout<<"*";       
  19.                 }
  20.         cout<<endl;
  21.         }
  22. }
  23. int main()
  24. {               

  25. while(true)
  26.         {
  27.                 say_hello();
  28.                 triangle1();
  29.                
  30.                
  31.                
  32.                
  33.                
  34.                
  35.                 system("pause");
  36.         }       
  37.                 return 0;
  38.                
  39. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;





  4. void say_hello()

  5. {

  6.         cout<<"*======================*"<<endl;

  7.         cout<<"*歡迎使用璽安小星星軟體*"<<endl;        

  8.         cout<<"*======================*"<<endl;

  9. }



  10. void triangle1()

  11. {

  12.         cout<<"L形三角形"<<endl;

  13.         for(int i=1; i<=5; i++)

  14.         {

  15.                 for(int j=1; j<=i; j++)

  16.                 {

  17.                         cout<<"*";

  18.                 }

  19.                 cout<<endl;

  20.         }        

  21. }



  22. void triangle2()

  23. {

  24.     cout<<"倒L形三角形"<<endl;

  25.     for(int i = 1; i <= 5; i++)

  26.         {

  27.                 for(int k = 1; k <= 5 - i; k++)

  28.                 {

  29.                         cout<<" ";

  30.                 }

  31.                 for(int j = 1; j <= i; j++)

  32.                 {

  33.                         cout<<"*";

  34.                 }

  35.                 cout<<endl;

  36.         }  


  37. }
  38. void triangle3()

  39. {

  40.     cout<<"等腰三角形"<<endl;   

  41.     for(int i = 1; i <= 5; i++)

  42.     {

  43.          for(int j = 1; j <= 5 - i; j++)

  44.          {

  45.          cout << " ";

  46.          }

  47.          for(int k = 1; k <= (i * 2) - 1; k++)

  48.          {

  49.          cout << "*";

  50.          }

  51.          cout << endl;

  52.     }

  53. }
  54. void triangle4()
  55. {               
  56.                 cout<<"垂直翻轉L形三角形"<<endl;
  57.                 for(int i = 1 ; i <= 5 ; i--)
  58.                 {
  59.                         for(int j = 1 ; j <= i ; j++)
  60.                         {
  61.                                 cout<<"*";
  62.                        
  63.                         }
  64.                        
  65.                
  66.                
  67.                 }
  68.                 cout<<endl;
  69.                 system("pause");
  70.                 return 0;
  71. }
  72. void triangle5()                       
  73. {
  74.         {
  75.                                 cout<<"垂直翻轉等腰三角形"<<endl;
  76.                                 for(int i = 3; i >= 1; i--)
  77.                 for(int k=1;k<=3-i;k++)

  78.                 {

  79.                     cout<<" ";
  80.                                 }
  81.                                                                

  82.                 for(int j = 1; j <= i*2-1; j++)

  83.                 {

  84.                         cout<<"*";
  85.                                 }       
  86.                        
  87.                    
  88.                                
  89.                         cout<<endl;;

  90.         }

  91. }



  92. void triangle6()

  93. {               
  94.                 cout<<"菱形"<<endl;
  95.                 for(int i = -2; i <= 2 ; i++)
  96.                 {
  97.                        
  98.                                 for(int j = 1 ; j <=abs(i) ; j++)
  99.                         {
  100.                                 cout<<"*";
  101.                        
  102.                         }
  103.                         int k=(abs(i));
  104.                         for(int j = 1 ; j <= k*2-1 ; j++)
  105.                         {
  106.                                 cout<<" ";
  107.                        
  108.                         }
  109.                         cout<<endl;
  110.                 }
  111. }
  112. int main()

  113. {

  114.         while(true)

  115.         {

  116.                 say_hello();
  117.                 triangle1();
  118.                 triangle2();
  119.                 triangle3();
  120.         triangle4();       
  121.                 triangle5();
  122.         triangle6();
  123.         system("pause");        

  124.         }        

  125.         return 0;

  126. }
複製代碼

TOP

本帖最後由 林廷翰 於 2015-7-3 21:00 編輯
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. void say_hello()
  5. {
  6.         cout<<"*======================*"<<endl;
  7.         cout<<"*歡迎使用璽安小星星軟體*"<<endl;        
  8.         cout<<"*======================*"<<endl;
  9. }
  10. void triangle1()
  11. {
  12.         cout<<"L形三角形"<<endl;
  13.         for(int i=1; i<=5; i++)
  14.         {
  15.                 for(int j=1; j<=i; j++)
  16.                 {
  17.                         cout<<"*";
  18.                 }
  19.                 cout<<endl;
  20.         }        
  21. }

  22. void triangle2()
  23. {
  24.     cout<<"倒L形三角形"<<endl;
  25.     for(int i = 1; i <= 5; i++)
  26.     {
  27.             for(int k = 1; k <= 5 - i; k++)
  28.             {
  29.                     cout<<" ";
  30.             }
  31.             for(int j = 1; j <= i; j++)
  32.             {
  33.                     cout<<"*";
  34.             }
  35.             cout<<endl;
  36.     }
  37. }
  38.          
  39. void triangle3()
  40. {
  41.     cout<<"等腰三角形"<<endl;   
  42.     for(int i = 1; i <= 5; i++)
  43.     {
  44.          for(int j = 1; j <= 5 - i; j++)
  45.          {
  46.          cout << " ";
  47.          }
  48.          for(int k = 1; k <= (i * 2) - 1; k++)
  49.          {
  50.          cout << "*";
  51.          }
  52.          cout << endl;
  53.     }
  54. }
  55. void triangle4()
  56. {
  57.         cout << "垂直翻轉L形三角形" <<endl;
  58.         for(int i = 5; i >= 1; i--)
  59.         {
  60.                 for(int j = 1; j <= i; j++)
  61.                 {
  62.                         cout << "*";
  63.                 }
  64.                 cout <<endl;
  65.         }
  66. }
  67. void triangle5()
  68. {
  69.     cout << "垂直翻轉等腰三角形" << endl;   
  70.     for(int i = 5; i >= 1; i--)
  71.     {
  72.          for(int j = 1; j <= 5 - i; j++)
  73.          {
  74.          cout << " ";
  75.          }
  76.          for(int k = 1; k <= (i * 2) - 1; k++)
  77.          {
  78.          cout << "*";
  79.          }
  80.          cout << endl;
  81.     }
  82. }
  83. void triangle6()
  84. {
  85.     cout << "菱形" << endl;   
  86.     for(int i = 1; i <= 3; i++)
  87.     {
  88.          cout << " ";
  89.          for(int j = 1; j <= 3 - i; j++)
  90.          {
  91.          cout << " ";
  92.          }
  93.          for(int k = 1; k <= (i * 2) - 1; k++)
  94.          {
  95.          cout << "*";
  96.          }
  97.          cout << endl;
  98.     }
  99.     for(int i = 4; i >= 1; i--)
  100.     {
  101.          for(int j = 1; j <= 4 - i; j++)
  102.          {
  103.          cout << " ";
  104.          }
  105.          for(int k = 1; k <= (i * 2) - 1; k++)
  106.          {
  107.          cout << "*";
  108.          }
  109.          cout << endl;
  110.     }                                             
  111. }
  112. int main()
  113. {
  114.         while(true)
  115.         {
  116.                system("cls") ;
  117.                
  118.                
  119.                 say_hello();               
  120.                 int a;
  121.                 cout << "請選擇要顯示的三角形:" << endl;
  122.                 cout << "(1) L形三角形 " << endl;
  123.                 cout << "(2) 倒L形三角形 " << endl;
  124.                 cout << "(3) 等腰三角形 " << endl;
  125.                 cout << "(4) 垂直翻轉L形三角形 " << endl;
  126.                 cout << "(5) 垂直翻轉等腰三角形 " << endl;
  127.                 cout << "(6) 菱形 " << endl;
  128.                cout << "請選擇:";
  129.                cin >> a;
  130.                switch (a)
  131.                {

  132.                  case 1:
  133.                          triangle1();        
  134.                          break;
  135.                  case 2:
  136.                          triangle2();        
  137.                          break;
  138.                  case 3:
  139.                          triangle3();        
  140.                          break;
  141.                  case 4:
  142.                          triangle4();        
  143.                          break;
  144.                 case 5:
  145.                          triangle5();        
  146.                          break;
  147.                  case 6:
  148.                         triangle6();
  149.                         break;
  150.                 }
  151.                  system("pause");        
  152.         }
  153.                 return 0;
  154. }       
複製代碼

TOP

返回列表