 Hello friends, I am Sanjay Gupta. I welcome you on Sanjay Gupta Tech School. In this video, I'm going to explain how you can implement these three patterns with the help of C program. So before starting, if you go to detail or description of this video, so you will find various links related to playlist. So you can watch them to know programming in better way. So these playlists are having various kind of views. So do watch them. Now I'm going to explain this pattern first, then I will be converting it into this and then this. So here you can see all these three patterns are right angled pattern. So if I identify the logic for this pattern, so first I need to implement a loop so that I can count on which row number I am currently available or you can say how many rows I need to print to print this pattern. So right now, for example, I'm taking like we need to print only five rows, right? So I'm implementing first loop that will begin from one and it will repeat five times. So this is initialization, I is starting from one, this is condition, termination condition, I less than equals to five and it is increment part. So this loop will repeat five times. Now, if you see carefully, so here we need to put some spaces. Here we need to put some spaces. So in first row, four spaces are required in second row three, then two, then one and then zero. So before printing these digits, we need to print the spaces and then we can print the digits properly. So if you identify the logic, so here total five rows are printed and at the top row, you can see number of spaces are four. So if I create a logic, so it is five minus one, so it will be four. Then if I write five minus two, then our second row spaces will be available. Then five minus three, five minus four and five minus five. So this way you can see these values will be available. So five you can see five is number of rows. So if you are reading number of rows from users, so here you can put n or here also you can put n and this one, two, three, four, five will be available through I. So now I need to implement one more loop that will print the spaces and the condition will be five minus five. So now I am going to implement that loop. So it will start from one and its termination condition will be this and j plus plus and inside this loop, I am using a print up statement which will print our space. So inside these double quotes, you need to put a blank space, right? Now after completion of this loop, I have to print these digits. So for that I am going to print, I am going to implement one more loop. This will repeat items. Again, I am using a printer statement. So it will print value five that I am closing this after this I am writing one more printer which will print new line. So this way I implemented the complete logic to print that pattern. So now I am going to explain it line by line so that you can understand how it will be printed. So starting from at top, I is equals to one. So let's say I is one. Check the condition. It is true. Then we come to this loop. So it is starting from one and here we are checking the condition j less than equals to five minus I. So what is the value of five? It is one. So five minus I is four. So this loop will repeat four times and it will print four spaces and we require four spaces. So they will be printed, right? So here I presented space with hyphen or dash, but in real time if you provide a space in double quotes in this case, so that space will be printed automatically. Then after termination of this control will transfer to this. So it is starting from one K less than equals to I. So here you can see I is one. So this loop will repeat one time and it is also printing value five. So I is one. So one time one will be. Then after completion of this loop, this printer will print new line. So cursor will come to new line. Now we have to move here I plus plus. So this time you can see value of I is two. Then check this condition. It is true. Then we come to this loop. So I j is starting from one and here condition is five minus I. So this time value of I is two. So five minus two will be three. So it means this loop will repeat three times now and three spaces will be printed. And here you can see we require a piece. Right. So this way this this loop is efficient for printing the spaces and this condition is working properly. After completion of this loop, we come to this loop here K is starting from one. And if you check the condition K less than equals to I. So this time I is two. So this loop will repeat two times and two times it will be printing value of I. So right now I is two. So it will print two times. Right. So this way I hope you understood this loop we are using to print spaces and this loop we are using to print visits. And the first loop is controlling how many times we need to repeat the whole problem. Right. And if you are reading how many numbers, number of lines we need to print. So you can read that inside this and variable and wherever you are using pipe or you can replace that with N. So I hope you understood this logic how it is printing. Now we need to convert it into this logic. So if you want to convert it into this, so instead of printing I, you can simply print J here. You can simply print J here. Sorry. You can simply print K. Not J. You can simply print K. So this loop will be same. It will be printing spaces here also. But if we come here and let's say I is two. So if I is two, so at that time this loop will be two times starting from one and it will go to two. So first it will print one that is required at second row and then it will be incremented. So its value will be two and second time it will print two. So instead of printing I, that will print the same value in the same row. We need to print values starting from one to the digits that is equivalent to that row number. So if we are on second row, we need to print one, two. If we are on third row, we need to print one, two and three. So starting from one till the particular row number. So that you can do with the help of this thing. Right. Rest of the things will be same. Now if we move to here, so again space logic will be same. We just need to print the digits in continuous order. One, two, three, four, five, six, seven, eight, nine, ten, eleven, twelve, thirteen, fourteen, fifteen. So here we need a new variable. Here we need a new variable. I'm removing this and here let's say I'm using one variable L and its initial value is one. Its initial value is one and here I'm using L. So L will be printed and after just print F I'm going to increase its value by one. I'm going to increase its value by one. So if I is one, if I is one, then this loop will create spaces for types. Then we come to here, it will repeat one time only. So L will be printed, L is one, so it will be printed. Then L will be incremented. So initially L is one, but now it will be up to two. So this is the single rotation. We are printing value L and simultaneously we are increasing it by one. Then I will be two. In next rotation I will become two. Then this loop will repeat five minus two, three times. Then it will print three spaces for second row. Then we come here. This time it will repeat two times because value of five is two and see last value of L is two. So first it will print two. Then it will be incremented to three. So when we are printing value of L as two and we are incrementing it up for three. So this is a single rotation. These two steps are performing one rotation right now. So one more rotation is available. So L will be printed as three because its value is three and then it will be incremented to four. So printing of L and incrementing its value by one. Together they are a single step. So if this loop is repeating two times. So print L will work two times and increment will work two times. So that current values will be printed. So it is completed the new line. Then I will be incremented to three. So when we will be reaching to this loop. So L will be starting from four. And here you can see we require two. So this way you can print these patterns. So this space loop is important. And after completion of this loop you can implement a loop which will print the digits accordingly. So in all three cases you saw first and second loops are same. We didn't change anything in these two loops. We just changed the third loop so that we can implement variety of logic. So I hope you understood whatever I explained in this video. If you want to watch more programming related videos look at open mic channel. Go to playlist and there you can watch videos related to programming. I have uploaded more than 1000 videos on my channel. So do watch them and thank you for watching this video.