0% found this document useful (0 votes)
27 views2 pages

2.1 Mirror Number Pattern Hint

This document explains how to print a mirror number pattern given an input number N. It provides the problem description, approach to solve it with pseudo code, and dry runs the code for an example input of N=4.

Uploaded by

bihaj41825
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views2 pages

2.1 Mirror Number Pattern Hint

This document explains how to print a mirror number pattern given an input number N. It provides the problem description, approach to solve it with pseudo code, and dry runs the code for an example input of N=4.

Uploaded by

bihaj41825
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Mirror Number Pattern

Problem Description: ​You are given with an input number N, then you have to print the given
pattern corresponding to that number N.
For example if N=4
Pattern output : 1
12
123
1234

How to approach?
1. Take N as input from the user.
2. Figure out the number of rows, (which is N here) and run a loop for that.
3. Now, figure out how many columns are there in ith row and run a loop for that within
this. Here, first you need to run a loop to print the spaces too.
4. Now, figure out “What to print?” in a particular (row, column). It can depend on the
column number, row number or N.

Pseudo code for the given problem:


input=N
i=1
While i is less than or equal to N:
spaces=1
While spaces is less than (n-i):
print(‘ ‘)
Increment spaces by 1
j=1
While j is less than or equal to i:
print(j)
Increment j by 1
Increment i by 1
Add a new line here

❏ Let us dry run the Code for N=4


● i=1(<=4)
➔ 4-1=3 spaces are getting printed first.
➔ j=1(<=1), so print=1+1-1=1
➔ j=2 (>1), move out of the inner loop with a new line

● i=2(<=4)
➔ 4-2=2 spaces are getting printed first.
➔ j=1 (<=2), so print 1
➔ j=2 (<=2) , so print 2
➔ j=3(>2), move out of the inner loop with a new line

● i=3(<=4)
➔ 4-3=1 space is getting printed first.
➔ j=1(<=3), so print 1
➔ j=2(<=3), so print 2
➔ j=3(<=3), so print 3
➔ j=4(>3), move out of the inner loop with a new line

● i=4(<=4)
➔ 4-4=0 no space is getting printed.
➔ j=1(<=4), so print 1
➔ j=2(<=4), so print 2
➔ j=3(<=4), so print 3
➔ j=4(<=4), so print 4
➔ j=5(>4), move out of the inner loop with a new line

● i=5(>4), move out of the loop

So , final output:
1
12
123
1234

You might also like