I found a way to display the top half of the triangle ending at 18 with a nested for loop. I cannot figure out how to display the bottom half in a nested for loop as well (it has to be in a nested for loop). Also, how to make the the colors interchange from green and red? Any tips?
Here's what I have:
int n1, n2, n3;
// Top Triangle nested for loop
for (n1 = 2; n1 <=18; n1++)
{
for (n2 = 2; n2 <= n1; n2++)
{
Console.Write("{0} ", n2);
n2++;
}
n1++;
Console.WriteLine();
}
// Bottom triangle nested for loop
// This is where I'm stuck
for (n1 = 2; n1 <= 18; n1++)
{
for (n2 = 2; n2 <= n1; n2++)
{
Console.Write("{0} ", n2);
n2++;
}
n1++;
Console.WriteLine();
}
for (n1 = 2; n1 <= 18; n1++)
{
for (n2 = 2; n2 <= 18 - n1; n2++)
{
Console.Write("{0} ", n2);
n2++;
}
n1++;
Console.WriteLine();
}