 Hello friends, I am Sanjay Gupta. I welcome you on Sanjay Gupta Tech School. In this video, I'm going to explain these two patterns. So I will be implementing two separate programs in C so that you will understand how these patterns to print deserts in form of binary on output screen can be implemented. So before starting of the explanation, if you go to the details or description of this video, you will find links of various places. So you can follow them to watch various programming related video. Now I'm going to explain the first pattern. So we need to understand the logic first. So here you can see we have multiple rows, right? And in each row, we have visits, either one or zero. So if we talk about first row, so you will see only one we need to print. Then in second row, we need to print one, then zero. Then in third row, we need to print one, zero, one. So here you can identify a common pattern. Like at the starting of each one, we are going to print one, then zero, then again one, then zero. So it means if we are printing a particular row, so its odd positions will be printing one and its even positions are printing zero. So if we talk about this, if we talk about this row, so you can see odd positions are printing one and even positions are printing zero. So this way we need to identify the logic. So here total two loops will be implemented. So one will be for rows and second will be for printing columns. So now I'm going to implement rows. So this is first loop and this loop will repeat five times because we need to print five rows. If you want to print more than five rows, so here you can place a variable that you can read from the user. Now inside this, I'm going to write one more and this loop will depend upon i because here you can see in each row, if we are on third row, we need to print three digits. If we are on fourth row, we need to print four digits. So the j loop will depend upon the i. So j will actually print the digits and how many digits it has to print that will be decided by the row number will be decided by the i. So after implementation, I will explain you each and every line or step so that you can understand how these loops are working and how this pattern will depend. So now here I'm going to apply one condition. So if condition will be like if j is having odd position, if j is having odd position or value, then we need to print one otherwise zero. So I'm checking if j modulus to double equals to zero. So if value of j is completely divisible by zero, so it will print zero, else it will print one. Then after completion of this loop, I'm going to print new line. So this way this implementation is complete. So now I'm going to explain the complete execution cycle. So starting from here, initially i is one, then control bit transfer here to j loop. So here you can see condition is j less than equals to i and i is one. So this loop will repeat only one time. So value of i is one, divide one by two, so it is not divisible. So control bit transfer to else, else will print one. So this way this one will be printed. Now after completion of this loop, this printer will transfer control to new line. So cursor will be available to new line. Now i plus plus, so this time i will become two and this j loop will repeat two times. So first time value of j is one. So check one modulus to divisible by completely divisible or not. So if it is equals to zero, then it is completely divisible, but one is not completely divisible by two. So again one will be printed. Then j plus plus will take place because this time j is repeating two times. So two modulus two. Now this will provide the material zero. So zero equals to zero will be true. So it will print zero. So you saw j is, j has been repeated two times after completion printer will print new line. So control will be transferred to third line. Now I will again implement so its value is three and j will repeat three times. So first, second and three. So initially it will be one, then this condition will be false. So it will print one. When j will be two, the condition will be true and it will print zero. When j will be three, its condition will be false and again it will print one. So this way based on value of j, we are deciding whether to print zero or one. So if j is having odd values, we are printing one. And if j is having even values, then we are printing zero. So this way you understood how this pattern is printed on output screen with the help of this program. Now coming to the second pattern. So here you will see one more change. First and fifth rows are starting from one, then after starting one, they are printing zero, then one, then zero and then one. If we talk about this second row and fourth row, so they are starting from zero, then printing one, then zero and then one. So it means we need two conditions here, like we are printing odd row or even row and then we need to decide we are printing odd column or even column. So in this, we only decided that rather we are printing odd column or even column because we decided it vertically. So vertically we need to identify columns. So we identified which column we are printing even or odd. But rows are printing similar kind of values. But here each row or you can say even rows are starting from zero and odd rows are starting from one and then they are printing one zero continuously. So this way we need to apply different logic here. So I am going to implement that. So again, these two loops will be enough. But we need to apply one more condition here. So this I is pointing to the row and J is pointing to the column. So if we are inside J, so first we need to apply this. So this if and ends, right. So this is a block and this is another block. So here we are dividing I by two. If I is completely divisible by two, it means we are on even row. Otherwise we are on odd row. Now if we are on even row, so we need to first print zero and then print one. So zero one, zero one. So if we see the column, so odd columns are printing zero and even columns are printing one. So inside this I am applying this logic. If J is divided by two and its remainder is equals to zero. So then we need to print one. So here inside printer I am printing one and else I am printing zero and again implement this here. So if J modulus two W equals to zero. So this is for odd rows. This is for odd rows. So here you can see if J is completely divisible by two then we need to print zero otherwise one. So with this if I am going to print zero and if we write as so here we need to print one. So this way this loop is completed and after this I need to write one print as so that we can print new line and then first loop will be completed. So this is I, this is J, and inside J loop we have two parts so that we can print this back. So now I'm going to explain this. So let's say I am going to print this photo and this fifth row, right. So if I am going to print four, so you will understand one logic if I am going to print fifth row so you will understand another law. So let's say I is four. Let's say I is four and 123, first, second, third rows are already printed for explanation purpose. I am explaining one even row and one odd. So let's say I is four. So J will start from one and it will go to four. So J will repeat totally four times, right. Now, when J is one, let's say J is one. So we will go inside the loop, check this condition. I modulus two. So I is four. It means we are printing even row. So if I is successfully divisible by two, then we need to run this if otherwise else. So in this case, I will be divisible by two. So when I is even, when I is even, so this block will run and when I is odd, so this block will run, right. So I is four. So every time this block will run. And here we need to check the value of J. So right now J is one, which is not divisible by two. So what will be printed? Zero and we want zero. Then J will be incremented. It is two. Again, check this condition. It will be true. It is I is four. So check this J is two. So two modulus two. So this time one will be printed. Again J will be incremented. J is three. So this time condition will be false. So zero will be printed. Again J will be incremented. So it is four. So four modulus two. Result will be equals to zero. So one will be printed. So when I is even, so this will work and accordingly J will be checked if it is completely divisible then one will be printed otherwise. So here you can see on even position ones are printed and odd positions are printed zero. Now this loop will complete after repeating four times. New line will be printed. Then I plus plus and this time I is four. So this time I is five. So J loop will repeat five times. And if J is repeating five times, so every time value of I will be five and five is odd number. So it means this condition will be false and this L block will run now. This L block will run now. So in case of I, if it is odd, so this L block will run. So again, we need to start J from one. So if J is one, so we are on L, so one modulus two. It is not divisible. So it will be printing one. So we want one. Then J will be two. So two, it is completely divisible. So it will print zero. That again J will be incremented. So this time J is not divisible. So again one. So this way all these values will be different. So you can see here, we are printing one zero. Here we are printing zero one. So we are just switching the result according to the value of J. So this block is for even rows and this block is for odd rows. And this way, if you implement this complete program, so this kind of pattern will be displayed on output. So I hope with this explanation, you have understood how these patterns will be printed on output scheme. So if you want to watch more programming related videos, you can go to details and description of this video. There you will find links of various players so you can watch them. And those players are also available on my channel. So do watch them. And I hope you understood whatever I explained in this video. Thank you for watching this video.