#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
int i=1,
StarinLine=-1,
StarVariable,
space,
N;
cout << "Enter the number (should be an Odd Number) for the height of the Diamond: ";
cin >> N;
while( N<=0 || N%2==0 )
{
cout << "Wrong Input! Enter again: ";
cin >> N;
}
cout << "The Diamond Pattern is:\n";
space=N;
while( i<=N )
{
if( i<=(N/2+1) )
{
StarVariable=1;
StarinLine+=2;
space-=1;
cout << setw(space);
while( StarVariable<=StarinLine )
{
if(StarVariable==1 || StarVariable==StarinLine)
cout << "*";
else
cout << " ";
StarVariable++;
}
}
else
{
StarVariable=1;
StarinLine-=2;
space+=1;
cout << setw(space);
while( StarVariable<=StarinLine )
{
if(StarVariable==1 || StarVariable==StarinLine)
cout << "*";
else
cout << " ";
StarVariable++;
}
}
cout << endl;
i++;
}
return 0;
}
No comments:
Post a Comment