C
What is pattern in C | How to print pattern
hi everyone welcome to coding idea
What is printed pattern?
this is Seamus in the last session wediscussed some of the patterns printing
in a C language so now we will see some
more discussions on how to print the
patterns different types of patterns
okay so now today pattern is so this is
five stands for stands three two one
this is a pattern we are going to print
now in how many ways we can print right
we use a so modifier operators and two
iterators we are using nothing but two
for loops we are using right and based
on our increment operators and decrement
operators in different ways we can print
this pattern how just look at this how
many rows we have totally files so outer
loops should repeat five times less than
or equals to 5 I plus plus because in an
outer loop and in a inner loop I am
using modify operator that is an
increment operator plus plus an X inner
for loop J value so what is that
initialization so what is the condition
and next one incrementation is a plus
plus only this is inside we are printing
print F star skeleton already we know a
next one after printing one row we need
to send the control to next line so
How to print pattern
newline character here we are givingright here it is so I value is a 1 so J
well I mean I is less than or equal to
Phi condition true the control move
inside with I value 1 and here it is how
many stars it should print means 5 stars
it should print 5 stars so what is the
logic we need to write means here it is
I value starts with J value starts with
I J is less than or equals to 5 see look
at this I value starts with 1 so J value
also starts with the I value so what is
the I value here 1 1 is less than or
equal to Phi condition true the control
move inside and it will print the star
first star it will print
next J value will increase so J value
become - J value become - 2 is less than
or equals to Phi condition true
so come inside it will print in the
second star next when J value three four
five so whenever J value becomes six so
then inner for loop execution will be
terminated and then the control come out
of the for loop and it will print the
slashin nothing but a newline character
it will bring so that it will send the
control to next line whenever outer for
loop execution completed once one
iteration completed then it will go for
second iteration so that is I value will
increase by 1 I plus plus here it is I
value become 2 I will you become to the
control come inside see again J value
restarts with the I so now what is that
I value is a 2 here it is very clearly
to showing that I value is a 2 so J
How do I print a loop pattern?
value again restarts with the 2 so firstcondition is a 2 is less than or equals
to 5 yes condition true so that it will
print 1 star it is first star it will
print here it is the first star and next
the value become 3 and next value become
4 and the value become 5 here it is a 4
iterations happening for all 4
iterations for every iteration 1 star it
will print so that four stars it will
print in the second row and next again
inner for loop will be terminated and
again newline character so that outer
loop executes I value become 3 I will
you become 3 so again J value restarts 3
2 3 3 with 3 1 iteration and next value
become 4 1 iteration value become 5 1
iteration so how many iterations here 3
iterations totally so 3 starts it will
print in the third row so like that it
will go okay so it will print in this
pattern so using modify operator
increment operator inner outer for loop
and increment operator enough inner for
loop so here instead of printing star
suppose if I print i value if I print I
value so what is the pattern it will
triangle number pattern in
so what will be the pattern here rightso look at the pattern here it is in the
first case I value is a one so five
times it will put into one five times
here it is a five stars it will print in
place of a star it will print the
background value of I so what is the
background value of I with one it is
executing so five times 1 4 times 2 3
times 3 2 times 4 and one time 5 it will
print this is a pattern it will print
instead of printing I well means instead
of printing star suppose if you print
the I value it will print this pattern
so instead of I suppose I am printing J
value then what will be the pattern what
will be the pattern look at this
whenever I value equals to 1 it starts
with 1 so 1 to 5 so 5 times it will
repeat 1 2 3 4 5 and second iteration I
value is a 2 so J value is also starts
with a 2 2 3 4 5 so total 4 iterations
so here it is a 2 3 4 5 next one I value
is a 3 so it starts with a 3 3 4 5 so 4
5 and 5 so this is a pattern okay so in
the inter use so not only they will ask
printing only stars in the process of
printing any patterns right instead of
printing stars they may ask the to print
some values like this such type of
patterns also they will ask no need to
worry about that if you are perfect in
how to print the patterns using
increment operators and decrement
operators it is very easy to print such
kind of patterns okay so now we will see
one more the same pattern we are
printing but in outer look we are using
I minus minus and inner loop also we are
using J minus - using decrement
operators how to print the same pattern
okay see see how to print the same
pattern 5 3 4 2 1 these stars so this
pattern how to print so using using
modify operators so that is a decreasing
write C for example so outer for loop
outer for loop we are taking so I value
so now in a decreasing order so I value
we know so total five rows I equals to
Phi I is greater than or equals to one I
How do I print a loop pattern
- - this is outer loop now just look atthe inner for loop here it is what is
the initialization and what is the
condition and what is the what is a
modify operator only modifier operator
is confirmed it
so that is J - - in outer for loop I - -
so what is the initialization and what
is the condition see and remain is
Kelton I am writing as usual printf so
we have printing star in inside for loop
and once one row printing is over it
will send the control to next line it
will send the control to next line how
to print now look at this five stars it
has to print so first I value starts
with a five so so J value J value
totally five stars it should print five
stars so J value starts with I J is
greater than or equal to one look at
this so first I value starts with a five
first I equals to five so I value starts
with a five five is greater than or
equals to one yes condition true come
inside it prints the first star first
our next J value is decreasing so J
value become four next value becomes
three next value become two next value
become one so total five times it is
repeating so whenever it is a zero then
it will fail for five iterations so five
stars it will print in the first row so
once first row printing is over it will
send the control to next line and outer
for loop will execute that is nothing
but I value become four I will you
become four again so J value starts with
the four now I value is a four so J also
starts with a 4 so 4 is greater than or
equals to one condition true next J
minus - it will become 3 it will become
2 it will become 1 so
for four iterations so it will print a
four stars in the second row second row
whenever it will become zero so then
inner loop will be terminated
again outer loop executes so I value
become three so in the third row
printing so again J value starts with
the three next value become two next
value become one so three iterations
three starts it will print in the third
row right so like that so to print this
pattern suppose if you are using
What is print and pattern?
decrement operator in the outer loop anddecrement operator in the inner loop so
these are the initialization values and
these are the conditions and same sorry
suppose here instead of star so suppose
if I print I value so what will be the
pattern it will print so very simple
first I value is a five in the first
iteration next two for next three next
to next one so in the inner loop inner
loop repeats five times right every time
we are printing I value only so what is
the I value first time five so five
times it will printer five next four
times it will print two four three times
three two times two and only one time is
a one it prints this pattern this
pattern will print sir instead of I
value suppose I am printing J value so
then what will be the output so first
time is a five it starts with a five
five four three two one
it will print five four three two one
next I value become four so it starts
with a four four three two one next I
value become three it starts with a
three three two one next to two one and
one this is the output okay so instead
of printing starts suppose if you print
I value or if you print a J value so
different patterns it will print so
these patterns also very very important
in the interview point of view okay so
this is so for example if you use a
increment operator in the outer loop and
decrement operator in the inner loop or
increment operator in the inner loop
What is pattern in C?
decrement operator in the outer loop nowwhat are the patterns and how to print
the same pattern
okay and such type of patterns how can
we print okay so that we will see in a
next session for more articel

Post a Comment
0 Comments