Shapes Printing Challenge: Numbers/Alphabets Triangles
Test your problem-solving skills in this challenging exercise.
We'll cover the following
Use nested for
loops for the upcoming tasks.
Printing triangle with numbers
In this section, we have a few coding challenges for you.
Challenge 1: Upright right triangle
Your code should print the following triangles. Consider h
could be any of the values between 1
to 10
.
Note: Make sure to write code depending on a specific value of h
.
Sample output
h = 5 h = 7 h = 9
1 1 1
1 2 1 2 1 2
1 2 3 1 2 3 1 2 3
1 2 3 4 1 2 3 4 1 2 3 4
1 2 3 4 5 1 2 3 4 5 1 2 3 4 5
1 2 3 4 5 6 1 2 3 4 5 6
1 2 3 4 5 6 7 1 2 3 4 5 6 7
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8 9
Good luck!
Get hands-on with 1200+ tech skills courses.