# Exercise 1

Create a loop to print following triangle made up of asterisks *.

         *
        **
       ***
      ****
     *****
    ******
   *******
  ********
 *********
**********
1
2
3
4
5
6
7
8
9
10

# Hint

To solve this problem, you will need two loops nested inside a loop.

 

 




 






for (int i = 0; i < 10; i++)
{
    for (int j = 10 - i; j > 0; j--)
    {
        Console.Write(" ");
    }

    for (int j /* write code */)
    {
        // Write code
    }
    // Write code
}
1
2
3
4
5
6
7
8
9
10
11
12
13

Notice that inside the loop i, we have two loops, first at line 3 and second at line 8. Both inner loops have variable j. It would work because both variables are in different scope.

Last Updated: Apr 22, 2020, 7:48 PM