#include <iostream>
#include <iomanip>
#include <cstdlib>
using namespace std;
int main(void)
{
int i,j,k,n,x;
cout << "請輸入n階階數" << endl;
cin >> n;
for(i=1;i<=n;i++)
{
for(j=1;j<=n-i;j++)
cout << " ";
cout << "*" ;
for(x=0;x<i*2-3;x++)
(i!=n)?cout << " " : cout<< "*";
if(i!=1)
cout << "*" ;
cout << endl;
}
system("PAUSE");
return 0;
}
執行結果
全站熱搜