close

 


#include<iostream>
#include<iomanip>
using namespace std;


void main( )
{
 int i, j, k, m=0,n=0,o=2,p=0;
 cout << "Please enter a number:";
 cin >> k;
 n=k-1;
 p=k-1;
 for (i = k ; i >= 1; i--) {
 cout << setw(k-i+1) << '*';  
 for ( j = i-1; j >= 1; j--)
  if ( j == 1)
   cout << " *";
  else
 cout << ((i==k) ? " *":"  ");


  cout << " ";


cout << setw(k-i+1+m) << '*';  
 for ( j = i-1; j >= 1; j--)
if ( j == 1)
cout << " * ";
  else
 cout << ((i==k) ? " *":"  ");


  m+=1;


 cout << endl;
}
for (i = 2 ; i <= k; i++) 
{
 cout << setw(k-i+1) << '*';
 for ( j = 1; j <= i -1; j++)  
  cout << (( j == i -1) ? " *" : "  ");


 cout << setw(k-i+1+n) << '*';
 for ( j = 1; j <= i -1; j++)  
  cout << (( j == i -1) ? " *" : "  ");
n-=1;
  cout << endl;
}

for (i = k-1 ; i >= 1; i--) 
{
  cout << setw(k-i+1) << '*';  
  for ( j = i-1; j >= 1; j--)  
   cout << ((j == 1) ? " *":"  ");

  cout << setw(k-i+1+o) << '*';  
  for ( j = i-1; j >= 1; j--)  
   cout << ((j == 1) ? " *":"  ");
o+=1;
   cout << endl;
}


 for (i = 2 ; i <= k; i++) 
 {
  cout << setw(k-i+1) << '*';
  for ( j = 1; j <= i-1; j++)  
    if (( j == i - 1 ) && (i != k))
     cout << " *";
    else
     cout << ((i==k) ? " *":"  ");


  cout << setw(k-i+1+p) << '*';
  for ( j = 1; j <= i-1; j++)  
    if (( j == i - 1 ) && (i != k))
     cout << " *";
    else
     cout << ((i==k) ? " *":"  ");
p-=1;
  cout << endl;
}
}

arrow
arrow
    全站熱搜

    nokia1314220 發表在 痞客邦 留言(0) 人氣()