In this tutorial, we will learn about the triangle Number pattern using nested loop in Cpp language.
We can use nested for loop in C++ to write coding for Squares, rectangles, Floyed triangle, Pyramid triangles and many other shapes.
In this tutorial, we will learn about some of the Floyd’s triangle shapes and how to write coding for that in C++ programming language.
Program to print triangle pattern using the number
C++ Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
#include<iostream> using namespace std; int main() { for(int i=0;i<=5;i++){ for(int j=0;j<=i;j++) { cout<<j; } cout<<endl; } return 0; } |
When the above code is compiled and executed, it produces the following results
1 2 3 4 5 6 7 8 |
0 01 012 0123 01234 012345 |