C++ Programming

C++ – Generates Triangle Shape Nested Loop

Write a program that generates the following output using a break statement with nested any loop.

1
4
6      9
8      12   16
10           …
12           …
14           …
…
…
..
…
24   36   48   60   72   84   96   108 120 132 144

Source Code:

#include<iostream.h>
#include<conio.h>
void main(){
    int x,y;
    for(x=1;x<=12;x++)
     {
      for(y=1;y<=x;y++)
       {
        cout<<x*y;
        }
        cout<<"n";
        }
        getch();
}

Output:

1
24
369
481216
510152025
61218243036
7142128354249
816243240485664
91827364554637281
102030405060708090100
112233445566778899110121
1224364860728496108120132144

Back to top button