C++ Program right angle triangle with a number that will repeat a number in a row
Write a program in C++ to make such a pattern like the right angle triangle with a number that will repeat a number in a row.
Flowchart of the right-angle triangle Program
C++ Program (Source Code) of the right-angle triangle Program
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
#include<iostream> using namespace std; int main() { int num , i, j; cout<<"Please Enter No. of Rows : "; cin>>num; i=1; do { j=1; do { cout<<i; j++;
} while(j<=i); i++; cout<<"\n"; } while(i<=num); } |
Output
Please Enter No. of Rows: 4
1
22
33
44
Excercise
Find the possible mistakes in the following Shamil’s Flow Table of the program of the right-angle triangle.
Suppose user input num = 3
Loop i | Loop J | What line will Execute | Actual work to do |
1 time
i = 1 |
1 time
j = 1 |
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17
18, 19, 20, 21, 22 |
coot<<i;
i =1 1 |
2 time
i=2 |
2 time
j=2 |
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17
18, 19, 20, 21, 9, 10, 11, 12, (13,14,15,16,17)2,18, 19,20,21,22, |
coot<<i;
i =2 22 |
2 time
i=3 |
2 time
j=3 |
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17
18, 19, 20, 21, 9, 10, 11, 12, (13,14,15,16,17)2,18,
19,20,21,22,21,9,10,11,12,(13,14,15,16,17)3,18, 19,20,21,22, |
coot<<i;
i =3 333 |