標題:
023_小星星圖形
[打印本頁]
作者:
游東祥
時間:
2015-5-30 11:13
標題:
023_小星星圖形
本帖最後由 游東祥 於 2015-7-4 09:14 編輯
寫一個程式,用來顯示幾種不同的小星星排列組合圖。
L型三角形:
*
**
***
****
*****
複製代碼
倒L型三角形:
*
**
***
****
*****
複製代碼
等腰三角形:
*
***
*****
*******
*********
複製代碼
作者:
黃璽安
時間:
2015-5-30 12:14
#include<iostream>
#include<cstdlib>
using namespace std;
void say_hello ()
{
cout<<"========================"<<endl;
cout<<"*歡迎使用璽安小星星軟體*"<<endl;
cout<<"========================"<<endl;
}
void triangle1 ()
{
cout<<"L形三角形"<<endl;
for(int i = 1; i <= 5; i++)
{
for(int j = 1; j <= i; j++)
{
cout<<"*";
}
cout<<endl;
}
}
int main ()
{
while (true)
{
say_hello ();
triangle1 ();
system ("pause");
}
return 0;
}
複製代碼
作者:
吳承勳
時間:
2015-5-30 12:16
#include<iostream>
#include<cstdlib>
using namespace std;
void say_hello()
{
cout<<"*======================*"<<endl;
cout<<"*歡迎使用璽安小星星軟體*"<<endl;
cout<<"*======================*"<<endl;
}
void triangle1()
{
cout<<"L形三角形"<<endl;
for(int i=1; i<=5; i++)
{
for(int j=1; j<=i; j++)
{
cout<<"*";
}
cout<<endl;
}
}
int main()
{
while(true)
{
say_hello();
triangle1();
system("pause");
}
return 0;
}
複製代碼
作者:
林廷翰
時間:
2015-5-30 12:16
#include<iostream>
#include<cstdlib>
using namespace std;
void say_hello()
{
cout<<"*======================*"<<endl;
cout<<"*歡迎使用璽安小星星軟體*"<<endl;
cout<<"*======================*"<<endl;
}
void triangle1()
{
for(int i = 1 ; i <=5 ; i++)
{
for(int j = 1 ; j <=i ; j++)
{
cout<<"*";
}
cout<<endl;
}
}
int main()
{
while(true)
{
say_hello();
triangle1();
system("pause");
}
return 0;
}
複製代碼
作者:
王翔
時間:
2015-6-6 11:57
#include<iostream>
#include<cstdlib>
using namespace std;
void say_hello ()
{
cout<<"========================"<<endl;
cout<<"*歡迎使用璽安小星星軟體*"<<endl;
cout<<"========================"<<endl;
}
void triangle1 ()
{
cout<<"L形三角形"<<endl;
for(int i = 1; i <= 5; i++)
{
for(int j = 1; j <= i; j++)
{
cout<<"*";
}
cout<<endl;
}
}
void triangle2 ()
{
cout<<"倒L形三角形"<<endl;
for(int i = 1; i <= 5; i++)
{
for(int k=1;k<=5-i;k++)
{
cout<<" ";
}
for(int j = 1; j <= i; j++)
{
cout<<"*";
}
cout<<endl;
}
}
int main ()
{
while (true)
{
say_hello ();
triangle1 ();
triangle2 ();
system ("pause");
}
return 0;
}
複製代碼
作者:
黃璽安
時間:
2015-6-6 12:08
#include<iostream>
#include<cstdlib>
using namespace std;
void say_hello ()
{
cout<<"========================"<<endl;
cout<<"*歡迎使用璽安小星星軟體*"<<endl;
cout<<"========================"<<endl;
}
void triangle1 ()
{
cout<<"L形三角形"<<endl;
for(int i = 1; i <= 5; i++)
{
for(int j = 1; j <= i; j++)
{
cout<<"*";
}
cout<<endl;
}
}
void triangle2 ()
{
cout<<"L形三角形"<<endl;
for(int i = 1; i <= 5; i++)
{
for(int k = 1; k <= 5 - i; k++)
{
cout<<" ";
}
for(int j = 1; j <= i; j++)
{
cout<<"*";
}
cout<<endl;
}
}
void triangle3 ()
{
cout<<"等腰三角形"<<endl;
for(int i = 1; i <= 5; i++)
{
for(int k = 1; k <= 5 - i; k++)
{
cout<<" ";
}
for(int l = 1; l <= i-1; l++)
{
cout<<"*";
}
for(int j = 1; j <= i; j++)
{
cout<<"*";
}
cout<<endl;
}
}
int main ()
{
while (true)
{
say_hello ();
triangle1 ();
triangle2 ();
triangle3 ();
system ("pause");
}
return 0;
}
複製代碼
作者:
王翔
時間:
2015-6-6 12:09
#include<iostream>
#include<cstdlib>
using namespace std;
void say_hello ()
{
cout<<"========================"<<endl;
cout<<"*歡迎使用璽安小星星軟體*"<<endl;
cout<<"========================"<<endl;
}
void triangle1 ()
{
cout<<"L形三角形"<<endl;
for(int i = 1; i <= 5; i++)
{
for(int j = 1; j <= i; j++)
{
cout<<"*";
}
cout<<endl;
}
}
void triangle2 ()
{
cout<<"倒L形三角形"<<endl;
for(int i = 1; i <= 5; i++)
{
for(int k=1;k<=5-i;k++)
{
cout<<" ";
}
for(int j = 1; j <= i; j++)
{
cout<<"*";
}
cout<<endl;
}
}
void triangle3 ()
{
cout<<"等要三角形"<<endl;
for(int i = 1; i <= 5; i++)
{
for(int k=1;k<=5-i;k++)
{
cout<<" ";
}
for(int j = 1; j <= i; j++)
{
cout<<"*";
}
cout;
for(int j = 1; j <=i-1 ; j++)
{
cout<<"*";
}
cout<<endl;;
}
}
int main ()
{
while (true)
{
say_hello ();
triangle1 ();
triangle2 ();
triangle3 ();
system ("pause");
}
return 0;
}
複製代碼
作者:
吳承勳
時間:
2015-6-11 17:06
#include<iostream>
#include<cstdlib>
using namespace std;
void say_hello()
{
cout<<"*======================*"<<endl;
cout<<"*歡迎使用璽安小星星軟體*"<<endl;
cout<<"*======================*"<<endl;
}
void triangle1()
{
cout<<"L形三角形"<<endl;
for(int i=1; i<=5; i++)
{
for(int j=1; j<=i; j++)
{
cout<<"*";
}
cout<<endl;
}
}
void triangle2()
{
cout<<"倒L形三角形"<<endl;
for(int i = 1; i <= 5; i++)
{
for(int k = 1; k <= 5 - i; k++)
{
cout<<" ";
}
for(int j = 1; j <= i; j++)
{
cout<<"*";
}
cout<<endl;
}
void triangle3()
{
cout<<"等腰三角形"<<endl;
for(int i = 1; i <= 5; i++)
{
for(int j = 1; j <= 5 - i; j++)
{
cout << " ";
}
for(int k = 1; k <= (i * 2) - 1; k++)
{
cout << "*";
}
cout << endl;
}
}
int main()
{
while(true)
{
say_hello();
triangle1();
triangle2();
triangle3();
system("pause");
}
return 0;
}
複製代碼
作者:
林廷翰
時間:
2015-6-13 12:19
#include<iostream>
#include<cstdlib>
using namespace std;
void say_hello()
{
cout<<"*======================*"<<endl;
cout<<"*歡迎使用璽安小星星軟體*"<<endl;
cout<<"*======================*"<<endl;
}
void triangle1()
{
cout<<"L形三角形"<<endl;
for(int i=1; i<=5; i++)
{
for(int j=1; j<=i; j++)
{
cout<<"*";
}
cout<<endl;
}
}
void triangle2()
{
cout<<"倒L形三角形"<<endl;
for(int i = 1; i <= 5; i++)
{
for(int k = 1; k <= 5 - i; k++)
{
cout<<" ";
}
for(int j = 1; j <= i; j++)
{
cout<<"*";
}
cout<<endl;
}
}
void triangle3()
{
cout<<"等腰三角形"<<endl;
for(int i = 1; i <= 5; i++)
{
for(int j = 1; j <= 5 - i; j++)
{
cout << " ";
}
for(int k = 1; k <= (i * 2) - 1; k++)
{
cout << "*";
}
cout << endl;
}
}
void triangle4()
{
cout<<"垂直翻轉L形三角形"<<endl;
for(int i = 1 ; i <= 5 ; i--)
{
for(int j = 1 ; j <= i ; j++)
{
cout<<"*";
}
}
cout<<endl;
system("pause");
return 0;
}
void triangle5()
{
{
cout<<"垂直翻轉等腰三角形"<<endl;
for(int i = 3; i >= 1; i--)
for(int k=1;k<=3-i;k++)
{
cout<<" ";
}
for(int j = 1; j <= i*2-1; j++)
{
cout<<"*";
}
cout<<endl;;
}
}
void triangle6()
{
cout<<"菱形"<<endl;
for(int i = -2; i <= 2 ; i++)
{
for(int j = 1 ; j <=abs(i) ; j++)
{
cout<<"*";
}
int k=(abs(i));
for(int j = 1 ; j <= k*2-1 ; j++)
{
cout<<" ";
}
cout<<endl;
}
}
int main()
{
while(true)
{
say_hello();
triangle1();
triangle2();
triangle3();
triangle4();
triangle5();
triangle6();
system("pause");
}
return 0;
}
複製代碼
作者:
王翔
時間:
2015-6-13 12:21
#include<iostream>
#include<cstdlib>
#include<cmath>
using namespace std;
void say_hello ()
{
cout<<"========================"<<endl;
cout<<"*歡迎使用璽安小星星軟體*"<<endl;
cout<<"========================"<<endl;
}
void triangle1 ()
{
cout<<"L形三角形"<<endl;
for(int i = 1; i <= 5; i++)
{
for(int j = 1; j <= i; j++)
{
cout<<"*";
}
cout<<endl;
}
}
void triangle2 ()
{
cout<<"倒L形三角形"<<endl;
for(int i = 1; i <= 5; i++)
{
for(int k=1;k<=5-i;k++)
{
cout<<" ";
}
for(int j = 1; j <= i; j++)
{
cout<<"*";
}
cout<<endl;
}
}
void triangle3 ()
{
cout<<"等要三角形"<<endl;
for(int i = 1; i <= 5; i++)
{
for(int k=1;k<=5-i;k++)
{
cout<<" ";
}
for(int j = 1; j <= i; j++)
{
cout<<"*";
}
cout;
for(int j = 1; j <=i-1 ; j++)
{
cout<<"*";
}
cout<<endl;;
}
}
void triangle4 ()
{
cout<<"垂直翻轉L形三角形"<<endl;
for(int i=1;i<=5;i++)
{
for(int j=1;j<=6-i;j++)
{
cout<<"*";
}
cout<<endl;
}
}
void triangle5 ()
{
cout<<"等腰翻轉三角形"<<endl;
for(int i=3;i>=1;i--)
{
for(int j=1;j<=3-i;j++)
{
cout<<" ";
}
for(int k=1;k<=i*2-1;k++)
{
cout<<"*";
}
cout<<endl;
}
}
void triangle6 ()
{
for(int i=-2;i<=2;i++)
{
for(int j=1;j<=abs(i);j++)
{
cout<<" ";
}
for(int k=1;)
}
}
int main ()
{
while (true)
{
triangle6 ();
system ("pause");
}
return 0;
}
複製代碼
作者:
吳承勳
時間:
2015-6-15 16:58
#include<iostream>
#include<cstdlib>
using namespace std;
void say_hello()
{
cout<<"*======================*"<<endl;
cout<<"*歡迎使用璽安小星星軟體*"<<endl;
cout<<"*======================*"<<endl;
}
void triangle1()
{
cout<<"L形三角形"<<endl;
for(int i=1; i<=5; i++)
{
for(int j=1; j<=i; j++)
{
cout<<"*";
}
cout<<endl;
}
}
void triangle2()
{
cout<<"倒L形三角形"<<endl;
for(int i = 1; i <= 5; i++)
{
for(int k = 1; k <= 5 - i; k++)
{
cout<<" ";
}
for(int j = 1; j <= i; j++)
{
cout<<"*";
}
cout<<endl;
}
}
void triangle3()
{
cout<<"等腰三角形"<<endl;
for(int i = 1; i <= 5; i++)
{
for(int j = 1; j <= 5 - i; j++)
{
cout << " ";
}
for(int k = 1; k <= (i * 2) - 1; k++)
{
cout << "*";
}
cout << endl;
}
}
void triangle4()
{
cout << "垂直翻轉L形三角形" <<endl;
for(int i = 5; i >= 1; i--)
{
for(int j = 1; j <= i; j++)
{
cout << "*";
}
cout <<endl;
}
}
void triangle5()
{
cout << "垂直翻轉等腰三角形" << endl;
for(int i = 5; i >= 1; i--)
{
for(int j = 1; j <= 5 - i; j++)
{
cout << " ";
}
for(int k = 1; k <= (i * 2) - 1; k++)
{
cout << "*";
}
cout << endl;
}
}
void triangle6()
{
cout << "菱形" << endl;
for(int i = 1; i <= 3; i++)
{
cout << " ";
for(int j = 1; j <= 3 - i; j++)
{
cout << " ";
}
for(int k = 1; k <= (i * 2) - 1; k++)
{
cout << "*";
}
cout << endl;
}
for(int i = 4; i >= 1; i--)
{
for(int j = 1; j <= 4 - i; j++)
{
cout << " ";
}
for(int k = 1; k <= (i * 2) - 1; k++)
{
cout << "*";
}
cout << endl;
}
}
int main()
{
while(true)
{
say_hello();
triangle1();
triangle2();
triangle3();
triangle4();
triangle5();
triangle6();
system("pause");
}
return 0;
}
複製代碼
作者:
王翔
時間:
2015-6-24 20:44
#include<iostream>
#include<cstdlib>
using namespace std;
void say_hello()
{
cout<<"*======================*"<<endl;
cout<<"*歡迎使用璽安小星星軟體*"<<endl;
cout<<"*======================*"<<endl;
}
void triangle1()
{
cout<<"L形三角形"<<endl;
for(int i=1; i<=5; i++)
{
for(int j=1; j<=i; j++)
{
cout<<"*";
}
cout<<endl;
}
}
void triangle2()
{
cout<<"倒L形三角形"<<endl;
for(int i = 1; i <= 5; i++)
{
for(int k = 1; k <= 5 - i; k++)
{
cout<<" ";
}
for(int j = 1; j <= i; j++)
{
cout<<"*";
}
cout<<endl;
}
}
void triangle3()
{
cout<<"等腰三角形"<<endl;
for(int i = 1; i <= 5; i++)
{
for(int j = 1; j <= 5 - i; j++)
{
cout << " ";
}
for(int k = 1; k <= (i * 2) - 1; k++)
{
cout << "*";
}
cout << endl;
}
}
void triangle4()
{
cout << "垂直翻轉L形三角形" <<endl;
for(int i = 5; i >= 1; i--)
{
for(int j = 1; j <= i; j++)
{
cout << "*";
}
cout <<endl;
}
}
void triangle5()
{
cout << "垂直翻轉等腰三角形" << endl;
for(int i = 5; i >= 1; i--)
{
for(int j = 1; j <= 5 - i; j++)
{
cout << " ";
}
for(int k = 1; k <= (i * 2) - 1; k++)
{
cout << "*";
}
cout << endl;
}
}
void triangle6()
{
cout << "菱形" << endl;
for(int i = 1; i <= 3; i++)
{
cout << " ";
for(int j = 1; j <= 3 - i; j++)
{
cout << " ";
}
for(int k = 1; k <= (i * 2) - 1; k++)
{
cout << "*";
}
cout << endl;
}
for(int i = 4; i >= 1; i--)
{
for(int j = 1; j <= 4 - i; j++)
{
cout << " ";
}
for(int k = 1; k <= (i * 2) - 1; k++)
{
cout << "*";
}
cout << endl;
}
}
int main()
{
while(true)
{
say_hello();
triangle1();
triangle2();
triangle3();
triangle4();
triangle5();
triangle6();
system("pause");
}
return 0;
}
複製代碼
作者:
王翔
時間:
2015-6-27 12:01
#include<iostream>
#include<cstdlib>
using namespace std;
void say_hello()
{
cout<<"*======================*"<<endl;
cout<<"*歡迎使用璽安小星星軟體*"<<endl;
cout<<"*======================*"<<endl;
}
void triangle1()
{
cout<<"L形三角形"<<endl;
for(int i=1; i<=5; i++)
{
for(int j=1; j<=i; j++)
{
cout<<"*";
}
cout<<endl;
}
}
void triangle2()
{
cout<<"倒L形三角形"<<endl;
for(int i = 1; i <= 5; i++)
{
for(int k = 1; k <= 5 - i; k++)
{
cout<<" ";
}
for(int j = 1; j <= i; j++)
{
cout<<"*";
}
cout<<endl;
}
}
void triangle3()
{
cout<<"等腰三角形"<<endl;
for(int i = 1; i <= 5; i++)
{
for(int j = 1; j <= 5 - i; j++)
{
cout << " ";
}
for(int k = 1; k <= (i * 2) - 1; k++)
{
cout << "*";
}
cout << endl;
}
}
void triangle4()
{
cout << "垂直翻轉L形三角形" <<endl;
for(int i = 5; i >= 1; i--)
{
for(int j = 1; j <= i; j++)
{
cout << "*";
}
cout <<endl;
}
}
void triangle5()
{
cout << "垂直翻轉等腰三角形" << endl;
for(int i = 5; i >= 1; i--)
{
for(int j = 1; j <= 5 - i; j++)
{
cout << " ";
}
for(int k = 1; k <= (i * 2) - 1; k++)
{
cout << "*";
}
cout << endl;
}
}
void triangle6()
{
cout << "菱形" << endl;
for(int i = 1; i <= 3; i++)
{
cout << " ";
for(int j = 1; j <= 3 - i; j++)
{
cout << " ";
}
for(int k = 1; k <= (i * 2) - 1; k++)
{
cout << "*";
}
cout << endl;
}
for(int i = 4; i >= 1; i--)
{
for(int j = 1; j <= 4 - i; j++)
{
cout << " ";
}
for(int k = 1; k <= (i * 2) - 1; k++)
{
cout << "*";
}
cout << endl;
}
}
int main()
{
while(true)
{
system("cls") ;
say_hello();
int a;
cout << "請選擇要顯示的三角形:" << endl;
cout << "(1) L形三角形 " << endl;
cout << "(2) 倒L形三角形 " << endl;
cout << "(3) 等腰三角形 " << endl;
cout << "(4) 垂直翻轉L形三角形 " << endl;
cout << "(5) 垂直翻轉等腰三角形 " << endl;
cout << "(6) 菱形 " << endl;
cout << "請選擇:";
cin >> a;
switch (a)
{
case 1:
triangle1();
break;
case 2:
triangle2();
break;
case 3:
triangle3();
break;
case 4:
triangle4();
break;
case 5:
triangle5();
break;
case 6:
triangle6();
break;
}
system("pause");
}
return 0;
}
複製代碼
作者:
吳承勳
時間:
2015-6-27 12:03
#include<iostream>
#include<cstdlib>
using namespace std;
void say_hello()
{
cout<<"*======================*"<<endl;
cout<<"*歡迎使用璽安小星星軟體*"<<endl;
cout<<"*======================*"<<endl;
}
void triangle1()
{
cout<<"L形三角形"<<endl;
for(int i=1; i<=5; i++)
{
for(int j=1; j<=i; j++)
{
cout<<"*";
}
cout<<endl;
}
}
void triangle2()
{
cout<<"倒L形三角形"<<endl;
for(int i = 1; i <= 5; i++)
{
for(int k = 1; k <= 5 - i; k++)
{
cout<<" ";
}
for(int j = 1; j <= i; j++)
{
cout<<"*";
}
cout<<endl;
}
}
void triangle3()
{
cout<<"等腰三角形"<<endl;
for(int i = 1; i <= 5; i++)
{
for(int j = 1; j <= 5 - i; j++)
{
cout << " ";
}
for(int k = 1; k <= (i * 2) - 1; k++)
{
cout << "*";
}
cout << endl;
}
}
void triangle4()
{
cout << "垂直翻轉L形三角形" <<endl;
for(int i = 5; i >= 1; i--)
{
for(int j = 1; j <= i; j++)
{
cout << "*";
}
cout <<endl;
}
}
void triangle5()
{
cout << "垂直翻轉等腰三角形" << endl;
for(int i = 5; i >= 1; i--)
{
for(int j = 1; j <= 5 - i; j++)
{
cout << " ";
}
for(int k = 1; k <= (i * 2) - 1; k++)
{
cout << "*";
}
cout << endl;
}
}
void triangle6()
{
cout << "菱形" << endl;
for(int i = 1; i <= 3; i++)
{
cout << " ";
for(int j = 1; j <= 3 - i; j++)
{
cout << " ";
}
for(int k = 1; k <= (i * 2) - 1; k++)
{
cout << "*";
}
cout << endl;
}
for(int i = 4; i >= 1; i--)
{
for(int j = 1; j <= 4 - i; j++)
{
cout << " ";
}
for(int k = 1; k <= (i * 2) - 1; k++)
{
cout << "*";
}
cout << endl;
}
}
int main()
{
while(true)
{
int a;
system("cls");
say_hello();
cout << "請選擇要顯示的三角形" << endl;
cout << "1)L形三角形" <<endl;
cout << "2)倒L形三角形" <<endl;
cout << "3)等腰三角形" <<endl;
cout << "4)垂直翻轉L形三角形" << endl;
cout << "4)垂直翻轉等腰三角形" <<endl;
cout << "5)菱形" << endl;
cout << "請選擇" << endl;
cin >> a;
switch (a)
{
case 1:
triangle1();
break;
case 2:
triangle2();
break;
case 3:
triangle3();
break;
case 4:
triangle4();
break;
case 5:
triangle5();
break;
case 6:
triangle6();
break;
}
system("pause");
}
return 0;
}
複製代碼
作者:
黃璽安
時間:
2015-6-27 12:04
#include<iostream>
#include<cstdlib>
using namespace std;
void say_hello ()
{
cout<<"========================"<<endl;
cout<<"*歡迎使用璽安小星星軟體*"<<endl;
cout<<"========================"<<endl;
}
void triangle1 ()
{
cout<<"L形三角形"<<endl;
for(int i = 1; i <= 5; i++)
{
for(int j = 1; j <= i; j++)
{
cout<<"*";
}
cout<<endl;
}
}
void triangle2 ()
{
cout<<"倒L形三角形"<<endl;
for(int i = 1; i <= 5; i++)
{
for(int k = 1; k <= 5 - i; k++)
{
cout<<" ";
}
for(int j = 1; j <= i; j++)
{
cout<<"*";
}
cout<<endl;
}
}
void triangle3 ()
{
cout<<"等腰三角形"<<endl;
for(int i = 1; i <= 5; i++)
{
for(int k = 1; k <= 5 - i; k++)
{
cout<<" ";
}
for(int l = 1; l <= i-1; l++)
{
cout<<"*";
}
for(int j = 1; j <= i; j++)
{
cout<<"*";
}
cout<<endl;
}
}
void triangle4 ()
{
cout<<"垂直翻轉L形三角形"<<endl;
for(int i = 5; i >= 1; i--)
{
for(int j = 1; j <= i; j++)
{
cout<<"*";
}
cout<<endl;
}
}
void triangle5 ()
{
cout<<"垂直翻轉等腰三角形"<<endl;
for(int i = 3; i >= 1; i--)
{
for (int j = 2; j <= 1; j++)
{
cout << "*";
}
cout << endl;
}
}
int main ()
{
while (true)
{
int a;
system("cls");
say_hello ();
cout << "請選擇你要的三角形:" << endl;
cout << "1) L形三角形" << endl;
cout << "2) 倒L形三角形" << endl;
cout << "3) 等腰三角形" << endl;
cout << "4) 垂直翻轉L形三角形" << endl;
cout << "5) 垂直翻轉等腰三角形" << endl;
cout << "6) L形三角形" << endl;
cout << "請選擇:" ;
cin >> a;
switch(a)
{
case 1:
triangle1 ();
break;
case 2:
triangle2 ();
break;
case 3:
triangle3 ();
break;
case 4:
triangle4 ();
break;
case 5:
triangle5 ();
break;
}
system ("pause");
}
return 0;
}
複製代碼
作者:
林廷翰
時間:
2015-7-3 20:42
本帖最後由 林廷翰 於 2015-7-3 21:00 編輯
#include<iostream>
#include<cstdlib>
using namespace std;
void say_hello()
{
cout<<"*======================*"<<endl;
cout<<"*歡迎使用璽安小星星軟體*"<<endl;
cout<<"*======================*"<<endl;
}
void triangle1()
{
cout<<"L形三角形"<<endl;
for(int i=1; i<=5; i++)
{
for(int j=1; j<=i; j++)
{
cout<<"*";
}
cout<<endl;
}
}
void triangle2()
{
cout<<"倒L形三角形"<<endl;
for(int i = 1; i <= 5; i++)
{
for(int k = 1; k <= 5 - i; k++)
{
cout<<" ";
}
for(int j = 1; j <= i; j++)
{
cout<<"*";
}
cout<<endl;
}
}
void triangle3()
{
cout<<"等腰三角形"<<endl;
for(int i = 1; i <= 5; i++)
{
for(int j = 1; j <= 5 - i; j++)
{
cout << " ";
}
for(int k = 1; k <= (i * 2) - 1; k++)
{
cout << "*";
}
cout << endl;
}
}
void triangle4()
{
cout << "垂直翻轉L形三角形" <<endl;
for(int i = 5; i >= 1; i--)
{
for(int j = 1; j <= i; j++)
{
cout << "*";
}
cout <<endl;
}
}
void triangle5()
{
cout << "垂直翻轉等腰三角形" << endl;
for(int i = 5; i >= 1; i--)
{
for(int j = 1; j <= 5 - i; j++)
{
cout << " ";
}
for(int k = 1; k <= (i * 2) - 1; k++)
{
cout << "*";
}
cout << endl;
}
}
void triangle6()
{
cout << "菱形" << endl;
for(int i = 1; i <= 3; i++)
{
cout << " ";
for(int j = 1; j <= 3 - i; j++)
{
cout << " ";
}
for(int k = 1; k <= (i * 2) - 1; k++)
{
cout << "*";
}
cout << endl;
}
for(int i = 4; i >= 1; i--)
{
for(int j = 1; j <= 4 - i; j++)
{
cout << " ";
}
for(int k = 1; k <= (i * 2) - 1; k++)
{
cout << "*";
}
cout << endl;
}
}
int main()
{
while(true)
{
system("cls") ;
say_hello();
int a;
cout << "請選擇要顯示的三角形:" << endl;
cout << "(1) L形三角形 " << endl;
cout << "(2) 倒L形三角形 " << endl;
cout << "(3) 等腰三角形 " << endl;
cout << "(4) 垂直翻轉L形三角形 " << endl;
cout << "(5) 垂直翻轉等腰三角形 " << endl;
cout << "(6) 菱形 " << endl;
cout << "請選擇:";
cin >> a;
switch (a)
{
case 1:
triangle1();
break;
case 2:
triangle2();
break;
case 3:
triangle3();
break;
case 4:
triangle4();
break;
case 5:
triangle5();
break;
case 6:
triangle6();
break;
}
system("pause");
}
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/)
Powered by Discuz! 7.2