Thursday, November 27, 2014

C++ Program printing *-shape

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

int main()
{
int DecN , N;
cout << "Enter number for one line of X-shape: ";
cin >> N;
while( N<=0 || N%2==0 )
{
cout << "Wrong Input! Enter again: ";
cin >> N;
}

cout << "The X-Shape is:\n";
DecN=N;
for( int i=1 ; i<=N ; i++ )
{
cout << setw(25);
for( int j=1 ; j<=N ; j++)
{
if( j==i || j==DecN || j==((i+DecN)/2) || i==DecN )
cout << "*";
else
cout << " ";
}
cout << endl;
DecN-=1;
}
return 0;
}

No comments:

Post a Comment