 Hello friends, I'm Sanjay Gupta. I welcome you on Sanjay Gupta Tech School. In this video I'm going to explain how you can print these four patterns with the help of C program. So before we start, I want to share one information. So if you go in the details of this video, so you will find various links of players that you can go through and you can learn various programs related to C by following those links. So do watch them. Now I'm going to start to explain how we can print these four patterns. So first I'm going to pick this one then so let's say this is first, this is second, this will be third and this will be fourth. So first I'm going to explain how we can print this pattern. So let's understand its printing method. So here you can see in first row we have one start. In second row we have two starts, sorry two starts. In third we have three then four and then five. So we need to implement one loop so that we can decide on which row we are currently. And inside that loop we will implement one more loop that will decide how many starts will be printed in that particular loop. So let me write this solution now. So right now I'm assuming we need to print five rows. That's why I mentioned five here. If you want to print n number of rows. So you can use printables kind of before this for you and here you can find the variable in which you receive how many number of lines a user want to print for this pattern. So for explanation purpose I am right now using five. Now this loop is implemented. So this is first loop which will repeat five times. Right now inside this loop I'm going to implement one more loop. So here you can see its initialization is j equals to one. Now I'm mentioning its condition as j less than equals to i. So this is our second loop right now this first loop will be known as outer loop and the second loop will be known as inner loop. Now you need to understand how these loops work. So it will start from here then it checks its condition. So it is true. Now control transfers to here. So j will begin from one. Now see this condition carefully. Here j less than equals to i is mentioned. So first time i is one. So j is also one. So one less than equals to one. So this condition is true. So inside this we can write print f and inside double quotes you can write one star. So first time this loop will repeat one time. So it will display this first star. So condition is true. So from here we need to move here. Then after checking this condition this step will execute then control will transfer to j plus plus. So let's say it is 6th step. Now after this increment j will become 2. So now again check the condition 2 less than equals to 1. So it is false. So if we check this condition again so it will become false. So this inner loop will be terminated and here you can see one star is printed with this loop execution. Now we need to print our next two stars from new line. So after completion of this loop you can write one more print f and inside this print f you can use backslash n. So backslash n will move cursor to the new line. So after termination of this condition control will transfer to here. So a new line will be there. Then we will move to i plus plus. So after termination of this condition we are printing this and we are moving to here. So let's say this is 7th step. So this time value of i will be 2. So when i was 1 so we printed one star. Now value of i is 2. So check this condition again 2 less than equals to 5. So it is true again. Now we are moving to here. So whenever we increase outer loop and check its condition then again inner loop will start from the beginning. Inner loop will start from the beginning. So j will be initialized by 1 and it will check its condition. So this time j is 1 and i is 2. So how many amount of times this loop will repeat? 2. So here you can see i is 2. So j will begin from 1. So first time condition is 2. So 1 star will be printed. Then j plus plus will take place. So again you can see j is 2, i is 2. So 2 less than equals to 2. So again this condition is true. So 1 more star will be printed. So we can analyze that j loop is dependent upon the value of i. And i is pointing on which row we are currently and how many star we want to print. So after termination of this loop, then again new line will be printed. So we will move to this third line. Then i plus plus. So i will become 3. j will again start from the 1 and this time i is 3. So this time j loop will repeat 3 times. So 3 stars will be printed. So this way I hope you understood how we are able to print this first pattern with the help of this loop. So remember one thing, when outer loop executes once, then inner loop completes its whole cycle. Then outer loop is incremented by 1 and then again inner loop starts its execution and completes its rotation. So when i is 1, so j will repeat 1 time. When i is 2, j will repeat 2 times. When i is 3, j will repeat 3 times and so on. So j is completely dependent on the value of i. So this way we printed this pattern. Now we need to print this number 2. So now you don't want to do any logical changes. If you want to print this pattern like this, so you just need to change initial value of i, termination condition of i and i minus minus. That's all things will remain same. So let's say i is building from 5. So this time i is initially 5. So check this condition. i greater than equals to 1. So it is true. Then we will move to here. j is starting from 1 and condition is j less than equals to i. So what is the current value of i? This is 5. So now this j loop, first time will repeat 5 times. So 5 stars will be printed. Then after completion of this loop, control bit transfer to backslash n. Then i minus minus. So next time i will become 4. j will again start from 1. So this time it will repeat 4 times. So 4 stars will be printed, then its termination will be done, then printer will print new line and this way this pattern will be printed. So if you are able to print this one, so you can easily print this one by changing the rotation of i. So i hope you understood first and second one. Now we need to print the third pattern. So in case of third pattern you can see, first is left line and third is right line. So here you can see we need to print spaces also. So right now i am pointing spaces with this dash. So in first row you can see we need to print 4 spaces and 1 star. Then 3 spaces, 2 stars, 2 spaces, 3 stars, 1 space, 4 stars, 0 space, 5 stars. So number of stars are similar to this first pattern. What we need to add in this pattern? We just need to provide extra spaces and then we need to print the stars. So in this pattern we need to use this as it is. But before this loop we need to add one more loop so that we can print these spaces as well. So i am removing this one. So i remove this, i will begin from 1, its condition will be i as equals to 5 and again i am using i++. So let's understand the condition for space first. Then we will implement the loop. So if you see first row number of spaces are 4. If you see second row number of spaces are 3, then 2, then 1 and then 0. So there is a pattern in printing of space. First we need to print 4 spaces then 3, then 2, then 1 and then 0. And number of rows are 5. So we can say 5 minus 1, 5 minus 2, 5 minus 3, 5 minus 4 and 5 minus 5. If we implement this so these number of spaces will be printed. So 5 we know a number of rows and 1, 2, 3, 4, 5 we will identify with the help of i. So if we group them together so it will convert into 5 minus i. So with the help of this condition i will be implementing a loop so that will print the number of spaces. So now j equals to 1, j less than equals to n minus i and j plus plus and this loop will print space. So here you need to provide a blank space. Here you need to provide blank space between these double quotes and then you can close this one. So after closing this loop you can start third loop. So I am using variable k then k less than equals to i and k plus plus. So this loop will print these stars and I am closing this and after completion of this a new line should be printed and closing off this form. So now I am going to explain the rotation of this so that we can print the third pattern. So i is starting from 1, condition is true. So i is 1, condition is true, we are moving here. So this time only this loop will repeat because this is nested loop for i and it is independent. After completion of this loop we are going to execute this k1. So j is starting from 1. Now see this condition n minus i. So here in place of n I am putting 5 because right now we know number of rows are 5. So 5 minus i, so what is the value of 5? It is 1. So 5 minus 1 is 4. So how many number of times this loop will be 4 times and here how many spaces will be required? 4. So 4 spaces will be printed with this loop. Now we come to this loop. It is starting from 1, k less than equals to i. So what is the current value of 5? It is 1. So how many number of times it will be? One time only. So here you can see this 1 star is available. Here you can see 1 star is available which is printed. So this loop is complicated then we are on print tab so that we can have new line. Then i discuss. So i is right now 2. i value is 2. So again we are moving to here. So j is 1, j less than equals to 5 minus i. So what is the value of this expression? So 5 minus 2. So it will be 3. So this time 3 spaces will be printed. And here you can see value of i is 2. So it will be 2 times. So 2 stars will be printed. So this way you will be able to print pattern number 3. Now i am going to print this 4 pattern. So i guess you can easily print this one. So this is the reverse of this one. So here we can start it from 5. Condition will be this. And here we need to put this i minus 1. So if you iterate this one. So this pattern will be printed automatically. So if you are able to print first pattern and third pattern. Then you can just change the execution cycle of first loop. You will be having second and third pattern automatically. So i hope you understood whatever i explained in this video. If you want to watch more videos related to programming. So you can open my channel and go to playlist. So there are various programming related videos are available. So i uploaded more than 1000 videos related to C, C++, data structure, Salesforce, Java and Python. So you can open my channel and watch those videos. And i hope you understood whatever i explained in this video. Thank you for watching this video.