 Hello friends. I'm Sanjay Bhukta. I welcome you on Sanjay Bhukta Tech School. In this video, I'm going to explain how you can print these two patterns. So here you can see what pattern is printing visits and setting pattern is printing alphabets. So here you can also notice these visits are increasing as well as they are decreasing in the pattern. So before start, I'm going to share one detail with you. So if you go to the detail of this video, you will find links of various programming related videos. So do follow them so that you can have various videos related to programming like this. So now after this information, I'm going to start to explain how you can implement the logic and code related to these patterns and think of them. So first I'm going to explain this one. So here you can see total number of rows are fine and number of rows that you want to print can be available in any number. So for example, right now we are taking a variable whose value will be 5. Further, you can read this value from user like how many number of rows you want to print. So I'm taking it as 5. So now I'm going to tell you how many loops are required to print this pattern. So our first loop will be to print or you can say to control on which number of row we are currently. So first loop will be for rows. Now we need to identify which will be the second loop. So here you can see we have some spaces to be printed. So if you see it carefully, so on the left hand side, we need to print these number of spaces. So in first row we have 4, then 3, then 2, then 1 and then 0. Why it is starting from 4 because number of rows are 5. If number of rows are more, then it will start from n minus 1. So we can implement the logic with the help of this. So second loop will be for space. Then here you can see if I divide it from here, if I divide it from here. So these all digits are printing in increasing order and after this line, all the digits are printed in decreasing order. So third loop will be for printing numbers in increasing order and fourth loop will be for printing numbers in decreasing order. So these four loops are required. So now after this requirement, I'm going to write a program for this implementation so that you can understand how it will look like. So I'm removing these. So now I'm writing all the requirements here. So first loop will be for rows. Second loop will be for printing spaces. Then third is for increment and fourth is for decrement order. So I wrote here this thing so that you can remember we need to implement whole things. So first I'm going to implement first loop that is for rows. So in place of n, I am directly using 5 here. So 5 means 5 number of rows to be printed. Then I need to implement the loop for space. So now we are going to identify the condition for this. So here you can see first we need 4 spaces that we went to, then 1 and then 0. So this we can identify through this 5-1. So here you can see I will be 1 first time. So 5-1 it will provide 4. Then second rotation I will be 2. So here it will be 5-2. So we can use this condition for implementing second loop. So I'm using this here and inside this loop I'm going to print space. So here remember one thing inside these double quotes you need to press or space bar one time so that spaces can be printed. And then I am closing this. So let's say value of i is 1. So control will go to here to check the condition. If condition is 2 then this loop will repeat. So here condition is 5-i. So i is 1. So it will repeat 4 times so 4 spaces will repeat. Then when i will become 2 so it will be 5-2. So 3 spaces will be different. So after completion of this program I'm going to explain this whole thing so that you can understand how it is printed. So let me implement 2 more loops one for implement and one for different. So after completion of this loop I am taking one more variable that is m and let's say I am starting it from 1. So initial value of m is 1. Now I am implementing one more loop which is k starting from 1. Then k laser equals to i and k++ inside this loop. I am going to print force and d k++. So here I am using force. Here I have to use m. Sorry in place of m I wrote k by mistake. So here I am using m++ so it is force increment. So first m will be printed and then its value will be increment. So here I close this loop. After this loop I am writing m equals to m-2. And then I am implementing one more loop. So this was the third loop for increment and now I am going to implement 4 loop which is for decrement. So this is l equals to 1, l less than equals to i and l++. So here notice it carefully it is l less than i, only less than not less than equals to. And inside this loop I am going to print value of m but I am using m-1. And this loop is closed here. Now just after closing this loop I am using one more printf that will be for backslash n. And then you can close this for loop. So after completion of this fourth loop you need to print backslash n and then you need to close this value base. So now I think it is visible to you. So after completion of this l for loop printf is written which is for backslash n. And then here you can see this for loop is complete. So this is one loop outer loop and it is having three more loops. So this is second one which is inner loop. This is third one which is also inner loop and this is fourth one which is also inner loop. Now I am going to explain from the beginning so that you can understand how it is printed. So here I am going to use all the variables. So first time i is 1. So starting from here and we need to check the condition that control will transfer to this loop. j is starting from 1. Now check this condition 5-i. So what is the value of i? It is 1. So 5-1 is 4. So how many times this loop will repeat? It will repeat 4 times. So 4 spaces will be printed. Now it will terminate and control will be here m equals to 1. So initially m is 1 now. Now go to this loop so it is k equals to 1, k less than equals to i. So what is the current value of i? It is 1. So how many times this loop will repeat? It will repeat one time only. So it will print value of n. It is post incremented. So first value of m will be printed and then it will be incremented. So it will print 1 and then m will become 2. And how many times we need to repeat this loop only one time. So in one rotation m is printed and then it is incremented. So this is called a one rotation. If we talk about two rotations. So first m will print then it will increment first rotation. Then m will print again and it will increment. So this will be called second rotation. That we are going to do when i will become 2. So now i hope you understood. One time m is printed that is 1 and m is incremented by 1. So it is 2. And this loop executed one time. Now control will transfer to this statement m equals to m minus 2. So current value of m is 2. So it will become 0. Then we come to this loop. So here check the condition l less than i. So what is l? 1. What is i? 1. So 1 less than 1 calls. So first time when i is 1. So this loop will not execute. And we don't want to do this because after one we don't want to print anything. And after completion of this loop printf slash m will take this. So slash m means new line. So this line is printed. And now we are here to print this second loop. So after completion of this statement we will move here. So this time i will become 2. So it means this whole title is executing for second time. Now we will be here. So j will again start from 1. Check the condition 5 minus i. So i is now 2. So 5 minus 2 is 3. So how many times this loop will repeat? 3 times only. And how many spaces are required? 3. So this is fulfilled. So I hope you understood this now. Now at this place m will be 1 again. So you need to assign 1 to m again. Then execute this loop. So right now i is 2. Right now i is 2. So how many times this loop will repeat? 2 times. Right? So we need to print m. Then we need to increase it. So I already told you. Printing of m and increment of m by 1 is 1 rotation. So m is printed. So it will print 1. And after printing it will be 2. After printing it will be 2. So right now we have performed only 1 rotation of k. Then again k will execute. So m will be printed. So m will print 2. Because its current value is 2. So 2 will be printed and it will become 3. So m printed 1. Then it incremented to 2 to 1 rotation. Then m printed value 2. Then it incremented to 3. So it is 2nd rotation. So this way this loop executed 2 times. And the last value of m is p. So this is important. Now m equals to m minus 2. It will be 1. So now you will understand why I started it from 1 here. And why I decremented it by 2 from here. So this time we are on this loop. So value of i is 2. Value of i is 2. And l is 1. So 1 less than 2. Condition is 2. So this loop will repeat our first time. So it will print m. So what is the current value of m? Is 1. And what we require? 1. So 1 will be printed. And after printing it will decrease it to 0. And how many times this loop will repeat only one time? Because i is 2. And l is 1. And we have less than. And l will be 2. And i is also 2. This loop will terminate. And nothing will print it. So again we came here for new line. So 2 rotations of this whole cycle is completed. Now third rotation. So i will be implemented to 3. I will be implemented to 3. Then check this condition 5 minus 3. It is now 2. So 2 spaces will be printed. So here you can see we require 2 spaces. Then m equals to 1. So again m will start from 1. Now I hope you can easily execute this one. So i is 3. So this loop will repeat 3 times. This loop will repeat 3 times. So 3 times means 3 times m will be printed. And along with it will be implemented. So initial value of m is 1. So here you can see 1 is printed. And m became 2. So this is first rotation. Then again m will print. And it will increment itself to 3. So this is second rotation. Then again m will print. And it will increase itself to 4. So this is third rotation. So this way 3 times m printed. And it incremented itself. So after completion of this loop. What is the final value of m is 4. And 1, 2, 3 also printed. Now you will understand how we did this. And y minus minus 3. So after completion of this loop m equals to m minus 2. So m will become 2. Now we came here. This time i is 3. So how many times this loop will repeat? It will repeat 2 times. So first it will print value of m. So value of m is 2. So 2 will be printed here. Now we want 1. So after printing 2, m will become 1. Because minus minus is here. So printing of m and its decrement is one step. Similarly we did here. So we printed 2 and decremented it to 1. So one rotation is completed. Now we need to repeat it again. So m will be printed. So 1 is printed on screen. And it will move to 0. So this way I hope you understood how these patterns are printed. So I explained you how these four loops are collaborating together to print the pattern for these loops. Now as we printed this, now we need to print these alphabets. So you need to do a small change on them. And everything will be printed. So I request you to implement this code first. And put main. So put this code inside me. Declare the required variable. So you will have this. After printing this, do a minor change and test whether I told you correctly or not. So after that minor change, this pattern will be converted into this. So what you need to do, you need to do this only. You need to start m with a. And you need to enclose it in single codes. And the data type of m for this is character. So here you need to declare this. And like this. Intent for this pattern. Right. And for this pattern, you need to declare MS. Yeah. Right. So by doing this minor change, you will be able to print this pattern. And here you can see m increment is done and decrement is done. So don't worry about this. So whenever we increase any alphabet, it automatically increases. And accordingly result will be printed. Now, if we are taking MS character variable, so we need to change the format specify as well. So here in case of person T, you need to use person T. So that proper alphabet will be printed. So increment decrement will be done in ask a value. But if you want to print the corresponding alphabets, then you can use person T. Right. So I hope this way you will be able to convert both the patterns and this board is for that purpose. I hope you understood whatever I explained in this video. If you like this video, you can open my channel, go to playlist and on after going to playlist, you will see various playlist related to various programming like available on my channel. So I uploaded more than 1000 videos on my channel related to computer programming. So do watch them and follow my YouTube channel so that it can be popular. I hope whatever I explained in this video you understood. So thank you and keep watching my videos. Thank you.