C
What is pattern printing? | What is pattern in C?
hi everyone welcome to coding idea
What is pattern printing?
this is cinemas so in this session so we
are going to discuss how to print
patterns so using loop control
statements in a C language so actually
most of the interview questions based on
these patterns how to print different
patterns star patterns in a two
dimensional way right how to print a
patterns okay see first I want to print
a simple pattern so starts printing with
are going to discuss how to print
patterns so using loop control
statements in a C language so actually
most of the interview questions based on
these patterns how to print different
patterns star patterns in a two
dimensional way right how to print a
patterns okay see first I want to print
a simple pattern so starts printing with
a fire rows and five columns so five
starts in each row
so five stars I want to print five stars
so we need to use a two for loops so one
loop outer loop is representing number
of rows and inner loop is representing
number of columns okay so two for loops
we are writing for outer loop I value
starts with one so how many rows are
there fire rows are there I equals to
one I equals to two I equals two three
four five fires I equals to 1 I is less
than 5 I plus plus I is less than 5 I
plus plus so now inside so inner for
loop represents how many number of
columns are in a each row how many stars
we are printing that it will represent
here J value starts with one two three
four five so now here J value starts
with one J is less than or equals to v
j+ + inside how it executes observe
first i value 1 1 is less than or equals
to 5 condition true
What is pattern in C?
so with I value 1 the control moveinside with I value 1 that is nothing
but first
so we are painting now first row I
equals to one the control come inside J
value starts with one J is less than or
equals to five that is nothing but J
equals to one the control move inside I
equals one J equals to 1 this is
intersection point so there we need to
print one star simply printf we are
printing the star how many times inner
loop executes right after execution of a
star printing again it will go and
increase that J value J value become 2 2
is less than or equals to 5 J value 2
still high value 1 only J value to 2 is
less than or equals to Phi condition
true with I value 1 and J value 2 second
star it will print second star next J
value become 3 J value 3 3 is less than
or equal to Phi condition true so here
it is it will third star it will print
next J value 4 4 2 star next J value 5 v
star
whenever J value is a 6 condition has
failed 6 is less than or equals to 5
condition has failed it will terminate
inner loop execution terminated inner
loop execution terminated means so first
row printing has been completed with I
value 1 so first row printing has been
completed then we should send the
control to the second row next row so
after execution of a for loop how to
How do I print a loop pattern?
send the control to next line thisprintf printf /n so newline escape
sequence slashin it will send the
control to next slide next line so how I
become - whenever it reaches the last
statement of outer loop last statement
again it will go under increase that I
value so now I value become 2 2 is less
than or equal to 5
conditioned true here it is I value to
again control move inside again J value
starts with one again J value restarts
with one so again with J value one two
three four five second row will print
next I value become three against a
value starts with one two five third row
elements it will print next I value
become four so fourth row values it will
print next I value become five fifth row
will print whenever I value becomes six
six is less than or equals to five
condition has failed so then it
terminates whenever outer condition has
failed then the control come out of the
program so like that we can print files
and Phi columns so with a full of stars
okay now I just want to print another
pattern see now I want to print this
pattern so what is the new pattern in a
first row I want to print only one star
in a second row I want to put into two
stars a third row three stars fourth row
four stars
ow do I print a pattern using a single loop?
fifth row five stars so these are hereobserve very clearly
whenever I value equals to 1 whenever
the control move inside with I equals to
1 in a previous case every time inner
loop is repeating 5 times so 5 5 stars
it is printing but now so how many times
inner loop should repeat sir how many
times inner loop should execute sir see
when I value is a 1 1 star it has to
print when I value to 2 stars I value 3
3 stars nothing but I stars it has to
print them so inner loop should execute
depends on size of the I value depends
on size of the I value see J value
starts with 1 but not up to 5 it is up
to I
it is up to I now look at this J value 1
1 is less than or equals to I value 1
condition to come inside with J equals
to 1 1 star it will print next whenever
J value become 2 2 is less than or
equals to 1 condition has failed
condition failed then inner loop will be
terminated then directly control command
execute that newline character it will
send the control to next line and
whenever it reaches end of the outer for
loop again here it is a modified
statement will increase I will you
become 2 now again J value starts with 1
J value starts with 1 1 is less than or
equal to one condition true so first
star it will print next J value become 2
up to 2 right 2 is less than or equal to
2 second time also condition true so
second star it will print next whenever
J value become 3 3 is less than or
equals to 2 condition has failed so then
it will send the control to newline ok
then I value become 3 so 3 stars it will
print i value for 4 times inner loop
1 2*3 4*5*6 pattern printing in c
executes next i value 5 5 times it willexecute so this is the way okay how to
print a simple pattern so this pattern
in how many ways we can print using
write modify statements nothing better
so modify operators write increment
operators and decrement operators in how
many ways we can print that we will see
in a next session
okay for more articel

Post a Comment
0 Comments