#include
void main ()
{
int width, horizPos, vertPos, beginHoriz, endHoriz;
char c;
cout << "Enter a character: ";
cin >> c;
cout << "Enter an integer: ";
cin >> width;
if ((width % 2) == 0) width = width+1;
horizPos = 0;
beginHoriz = width / 2;
endHoriz = beginHoriz;
while (beginHoriz >= 0)
{
while (horizPos < width)
{
if (horizPos < beginHoriz) cout << " ";
else if (horizPos <= endHoriz) cout << c;
else cout << " ";
horizPos = horizPos + 1;
}
cout << endl;
horizPos = 0;
beginHoriz = beginHoriz - 1;
endHoriz = endHoriz + 1;
}
horizPos = 0;
beginHoriz = 1;
endHoriz = width - 2;
while (beginHoriz <= width / 2)
{
while (horizPos < width)
{
if (horizPos < beginHoriz) cout << " ";
else if (horizPos <= endHoriz) cout << c;
else cout << " ";
horizPos = horizPos + 1;
}
cout << endl;
horizPos = 0;
beginHoriz = beginHoriz + 1;
endHoriz = endHoriz - 1;
}
}
void main ()
{
int width, horizPos, vertPos, beginHoriz, endHoriz;
char c;
cout << "Enter a character: ";
cin >> c;
cout << "Enter an integer: ";
cin >> width;
if ((width % 2) == 0) width = width+1;
horizPos = 0;
beginHoriz = width / 2;
endHoriz = beginHoriz;
while (beginHoriz >= 0)
{
while (horizPos < width)
{
if (horizPos < beginHoriz) cout << " ";
else if (horizPos <= endHoriz) cout << c;
else cout << " ";
horizPos = horizPos + 1;
}
cout << endl;
horizPos = 0;
beginHoriz = beginHoriz - 1;
endHoriz = endHoriz + 1;
}
horizPos = 0;
beginHoriz = 1;
endHoriz = width - 2;
while (beginHoriz <= width / 2)
{
while (horizPos < width)
{
if (horizPos < beginHoriz) cout << " ";
else if (horizPos <= endHoriz) cout << c;
else cout << " ";
horizPos = horizPos + 1;
}
cout << endl;
horizPos = 0;
beginHoriz = beginHoriz + 1;
endHoriz = endHoriz - 1;
}
}
No comments:
Post a Comment