Lecture 4: Solving Pattern Questions (Part-2)
We are going to solve 18 pattern questions in this video. In the last lecture,
we studied about the if else and while loop. We also did 2 pattern
questions. We are not able to find any relation but we know that it is simply
printing the counting So we can make a variable count , print it and then
increment it Let 's try to try this approach. This is the pattern which we
have to print now - Triangle pattern. We know that row = n. Also we can
notice that number of stars in a particular row is equal to the row number
which is 'i' Now let 's take a variable count=1 and we will print this count
and then increment it outside this loop. Outside this loop , we will enter a
new line and increment ' i' We will declare a variable inside this row loop
but outside the col loop. Then after printing it inside col loop , we will keep
on incrementing it by 1 There is an another method for this question But
first let 's write the code for this one We ca n't simply print row and
increment it , because then our program will misbehave. We just need to
think about the upper limit of row number and column number.
We have done 9 pattern questions. Let 's do some more questions to
understand this topic completely. Next pattern looks like this 1st obs - row
= n 2nd obs- A is mapped to 1 , B is mapping to 2 and so on. This time we
will run both loops from 1 to n because it is a square pattern. We got our
counting correct but just had to map 1 to ' A ' so to do so , we added ' A -1
on both sides , so to. do so. We just have to print ' A'+i -1 , but it will be
typecasted to integer so to avoid that. I will put this value inside a character
and then print it Then incremented col , added a new line outside the col
while loop and then incremented row too Simple You have to implement it
by yourself. Bhaiya: We have to find a relation for printing our answer. If
you are not able to do this question by yourself, then revise these first. We
can see their dependence on row number and col number. We know that it
is written in the reverse order. Also 'A ' will be there for sure. We will get
1
We are going to solve 18 pattern questions in this video. In the last lecture,
we studied about the if else and while loop. We also did 2 pattern
questions. We are not able to find any relation but we know that it is simply
printing the counting So we can make a variable count , print it and then
increment it Let 's try to try this approach. This is the pattern which we
have to print now - Triangle pattern. We know that row = n. Also we can
notice that number of stars in a particular row is equal to the row number
which is 'i' Now let 's take a variable count=1 and we will print this count
and then increment it outside this loop. Outside this loop , we will enter a
new line and increment ' i' We will declare a variable inside this row loop
but outside the col loop. Then after printing it inside col loop , we will keep
on incrementing it by 1 There is an another method for this question But
first let 's write the code for this one We ca n't simply print row and
increment it , because then our program will misbehave. We just need to
think about the upper limit of row number and column number.
We have done 9 pattern questions. Let 's do some more questions to
understand this topic completely. Next pattern looks like this 1st obs - row
= n 2nd obs- A is mapped to 1 , B is mapping to 2 and so on. This time we
will run both loops from 1 to n because it is a square pattern. We got our
counting correct but just had to map 1 to ' A ' so to do so , we added ' A -1
on both sides , so to. do so. We just have to print ' A'+i -1 , but it will be
typecasted to integer so to avoid that. I will put this value inside a character
and then print it Then incremented col , added a new line outside the col
while loop and then incremented row too Simple You have to implement it
by yourself. Bhaiya: We have to find a relation for printing our answer. If
you are not able to do this question by yourself, then revise these first. We
can see their dependence on row number and col number. We know that it
is written in the reverse order. Also 'A ' will be there for sure. We will get
1