利用巢狀回圈,將符號 * 整齊排列成如下圖之三角形:
 - #include<iostream>
- #include<cstdlib>
- using namespace std;
- int main()
- {
- 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;
- }
- system("pause");
- return 0;
- }
- /*
- 列 1 2 3 4 5
- 空 4 3 2 1 0
- 星 1 3 5 7 9
- */
複製代碼 |