You are on page 1of 21

Pattern Printing - 1

Lecture - 7

Raghav Garg
Ques : Print the given pattern
input
of of
1 2 3 4 5 user -
no. rows a no. columns
I
*****
2

***** no of lines no.


of things in
3
***** each eine

S stars in 'n'lines

line
m ->
no.
of stars in each

n Y
=
* *
*

->
* *
m 3
=

* * *

Solid Rectangle * * *
Ques : Print the given pattern

****
****
****
****
User input
-
n-side
of square

Solid Square
Ques : Print the given pattern
3
=
n2 n 1 =

n4 n
=

1234 12 I
123

1234 123 12

1234 123

1234
for lint : =1;i c n;i +)4
= +

I conti

Number Square
n 3
=

Output

I
·
1 2 3

· 123

· 123

i x4 B
=

j Nx
=
YX
& BYARB Y
Ques : Print the given pattern Output
·
X
n 4
=

i 4 & B Y
=

*
7 · XX
j xRXRBAx B Y
**
=

2 X

***
· X X
3

**** n 3
=

Star Triangle
Ques : Print the given pattern
n =
Y
stars n+1
Row of
=

mo. t no.

****
-
i

*** -it no.


of stars n+ 1 i
= -

**
* ↓ 2 3 Y


I *
*
* * 4

2 *
*
* 3

i 3

4
*

*
*
2

Star Triangle Reverse


Ques : Print the given pattern
for lint i= 1; i < =
n; i+ 3 [
1
+

I
for (intj= 1;j i;; 7
12
<= +
+
2

I coutj;
3 1 2 3

4 1 2 3 4
3
contende;

Number Triangle
Ques : Print the given pattern
A

nY
=

I 2 3 Y

I
1
2
13
3
135
Y 1357
L

Odd Number Triangle


Ques : Print the given pattern
n 4
=

656666 68

ABCD 234 65666768


ABCD
I
I

ABCD
1234

ABCD - 1 2 3 Y

I 234

#int:ASCII values

Alphabet Square
Ques : Print the given pattern (n 0ddS
=

1 2 3 4 S

-##
5
*
2##
*
*****
123 n 1
=

*
1 A* #
## #
#
3
*

*
2 x * Y
#
###
3 #* #

n 3
=

int mid= 1
1 +

Star Plus
Ques : Print the given pattern
I 2345
12345
* *
I 1 y

* *
2 X
2
-

*
- - -

3 x


- -

* *
- - -

X
-
y

*j *
- -
- - -

S - - -
S ---
X
i +
n
=
+
1

nS
=

Star Cross
*Ques : Print the given pattern
n Y
=

1 Extra variable +bahar of outer


look
23 int R =
1, k +
+

456
7 8 9 10

Floyd’s Triangle
*Ques : Print the given pattern
#I:Using entra variable
I
1
2
01 if (1%2! 1
101
=
0) + se start
3

u 0 1 0 1
else -0 se start

n 4
=
alternatively

Binary Triangle
*Ques : Print the given pattern
I
2345j
I
1 if (i j) 1
01
=
= -

3
101 if it; both odd -> 1

Y
0101 is; both even - 1

10 10 1
5
if (itj %2 0) -1
=
=
-

Binary Triangle
*Ques : Print the given pattern
123 Y

* spaces & starts


I #
#
#

Pop
L
2 ##
** loop
3 #
***
Y
**** #
#
# X

#
#
X A
I
# T X X

& &x *

n 4
=

Star Triangle Flipped


*Ques : Print the given pattern 2
1234j
!--- * 1)
** it(i j xn
= +

***
- -

3 -

Y
****
i

Star Triangle Flipped


3
n
Output

I
=

n -i 0
=

8 X
i x23
= - -

j xRBX2
=

8 -
**

* de
k b7
=

1 ·

! -
Ques : Print the given pattern

~
1- -

I
12
--
-

I
12

123
- -

I
-
-

-
123

1234
-

1234

Assignment
-
sharp

Number Triangle Flipped


What’s in the next lecture?
More patterns!

More interesting and with more fun!


Summarise:nested
-
-
loops
2) Square/rectangle be structure in Iton julton

A 44 A i1 n
2 Trangle
to
=

i 1toni
=

in iontri
R 1 to i
=

Maths
3)
Thank
You.

You might also like