# Exercise 3
Create a loop to print following triangle made up of asterisks *.
*
***
*****
*******
*********
***********
*************
***************
*****************
*******************
1
2
3
4
5
6
7
8
9
10
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 < 20; i+=2)
{
for (int j // write the code)
{
Console.Write(" ");
}
for (int j // write the code)
{
Console.Write("*");
}
Console.WriteLine("");
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14
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.
← Exercise 2 Exercise 4 →