I am having a little problem here, I want to draw a vertical pyramid like this:
O
OO
OOO
OOOO
OOOOO
OOOO
OOO
OO
O
But I can’t seem to figure out how to do it. All I get is:
O
OO
OOO
OOOO
OOOOO
OOOOOO
OOOOOOO
OOOOOOOO
OOOOOOOOO
Here is my code:
int width = 5;
for (int y = 1; y < width * 2; y++)
{
for (int x = 0; x < y; x++)
{
Console.Write("O");
}
Console.WriteLine();
}
There are ways to do this with two loops, but here is a way to do it with one, and without an
ifcondition: