this is the code i came up with, however, i dont think this is what Deitel are looking for, is this 'clever' use of nested loops?
Code:
using System;
namespace Ex5_8
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
int midspaces = 0, countd = 10, countu = 1;
for(int outer=0; outer<10; outer++, countd--, countu++)
{
for(int h=0; h<=outer; h++)//1st stars triangle needs to inc on each loop from 1 to 10
Console.Write('*');
for(int i=1; i<=countd; i++)
Console.Write(' ');//1st space triangle needs to dec from 9 to 0
for(int j=1; j<=countd; j++)
Console.Write('*');//2nd star triangle needs to dec from 10 to 1
for(int k=0; k<midspaces; k++)
Console.Write(' ');//middle space triangle needs to inc from 0 to 18
midspaces = midspaces+2;//in steps of 2
for(int l=1; l<=countd; l++)//3rd star triangle needs to dec from 10 to 1
Console.Write('*');
for(int m=1; m<=countd; m++)//4th space triangle needs to dec from 9 to 0
Console.Write(' ');
for(int n=0; n<countu; n++)//4th star triangle needs to inc from 1 to 10
Console.Write('*');
Console.WriteLine();//newline
}
}
}
}
which produces the following output
Code:
* ******************** *
** ********* ********* **
*** ******** ******** ***
**** ******* ******* ****
***** ****** ****** *****
****** ***** ***** ******
******* **** **** *******
******** *** *** ********
********* ** ** *********
********** * * **********
i would really appreciate some feedback, there must be someone reading this forum who has worked with for nested for loops
thanks in advance