 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 implement these two pyramid patterns. So in first, you can see at top one, as to this call star is printed, then three, five, seven and nine. And if we go to second pattern, so it is having nine, seven, five, three and one as to this call stars. So before starting, if you go to detail or description of this video, you will find links of pages playlist. So you can watch them to learn more programming. Right. So now coming on to this. So first I'm going to explain how you can print this pattern. And then we will do a minor change. And through that minor change, you will see how this pattern will be printed in form of this. Right. So first let's analyze this pattern, how it will be printed. So there will be total three loops that we are going to use to print this pattern. So first loop will identify a row number. So this way we can identify the row number one, two, three, four, five. So in this pattern, we have five rows. It means one loop will be there, which will be controlling on which row we are currently. Then after controlling the loop, sorry, row number, we need to identify like how we can print these are spaces. So if we go here, so here you can see these are the spaces. Here you can see these are the spaces. So in first row, you have four spaces, then three, then two, then one and then zero. So this is the row number and these are the spaces, right? So first loop will be for rows. Second loop will be for printing spaces. And third will be for printing these as well. So this will be identified like how many loops will be there. So now one by one, I will be implementing those so that you can understand how it will be. So first time implementing first loop, which will repeat five times because here we are going to print five rows of them. If you want to print more rows, then you can use printers kind of before the for loop. And you can read how many rows you want to print from the user in a variable and you can put that variable in place of five. So right now I am demonstrating it with the help of five only. Now inside this loop, I am going to implement one more loop which is starting from one. Now it's condition we need to frame. So this loop will be for printing spaces. So now let's identify the logic. You can see in first row we need four spaces because total number of rows are five. So we can write five minus one. So five minus one, four, so four spaces. Then we can write five minus two, five minus three, five minus two and five minus one. So if we, sorry, five minus four and five minus five. So if we write this logic in this way, so here you can see five is repeating as a five. So we can write five. Then one, two, three, four, five will be received two times. So we can convert this like this, five minus five. And if we calculate this, so we will be having these values. So these values are for printing number of spaces. So here I am writing J less than equals to five minus five. So J loop will depend upon this condition. And then J less than. Right. So this way you can see this loop is implemented here. Now inside this loop I can write printf and inside printf I'm putting a space so that that space can be printed and I'm doing this. So this is nested loop for I, this is nested loop for I, which will print the space. So after complete implementation, I will explain each and every step. So see the complete video so that you can understand how it will be implemented. So this is for space. Now I need to implement one more loop. So I'm going to implement it like K equals to one. So it is started from K. Now see here, number of s risks. So one, then three, then five, then seven, then nine. So we have odd numbers in this one, three, five, seven, nine and four. So here I'm writing a logic I into two minus one, I into two minus one. So this is simple. If we have natural numbers, one, two, three, four, five. If we multiply them to multiply them with two and subtract by one. So we will have four numbers. So I'm repeating again if we have natural numbers, we multiply them by two and subtract by one. So we will be having odd numbers. So let's calculate this one into two, two minus one, one, two into two, four, minus one, three, three to two, six, minus one, five, four into two, eight, minus one, seven, five into two, ten, minus one, nine. So with this way you can identify odd numbers. So I did say I is natural number which will receive from this loop multiplied by two and subtracted by. So this way you can have this pattern. So now I'm closing this with K plus plus. And inside this loop I need to print as to risk after completion of this loop. I need to print slash n and completion of idle. So this is the complete implementation. This one is outer loop. It is having two inner loops. So now I'm going to explain it from the beginning so that we can see how it is printed. So initially I is one. Initially I is one. So I am writing all the variables here so that you can go with me. So starting from here I is one. Check this condition. It is true. Then control will be transferred to this loop. Control will be transferred to this loop. So it is starting from one. Check this condition. Five minus i. So what is the value of i? It is one. So five minus one, four. So how many times this loop will be four times? So it will print four spaces. And how many space will be required? We require four spaces. So our requirement is fulfilled with this loop. After completion of this loop control will be transferred to this loop. Again, see initialization is one condition. k less than equals to i into two minus one. So what is i? One. So one into two, two minus one, one. So this loop will repeat one time. And it will print this as well. Then this loop will terminate. Print f will print new line. Then this next row we want to print from new line. So it is completed then i plus plus. So this time value of i is two. Check this condition. It is again true. Come on this loop. Starting from one, check this condition five minus i. So this time i is two. So five minus two is three. So this loop will repeat three times. So three spaces will be three. After completion of this loop, come to this loop. It is again starting from one. Now i is two. So two into two, four minus one, three. So it will repeat three times. And we require three spaces. So the three starts over. And after completion of this loop, new line will be printed. Then again i plus plus. This time i will be three. Five minus three means two. So two times repetition, two spaces. Then come here three into two minus six, five. So it will be five times. So you can see five stars are great. So this way, if you integrate it, complete five times. So this pattern will be printed. So I hope you understood this. How I explained this pattern implementation. Now after implementing this, if you want to convert it into this. So you need to do a minor change on in this loop. So you need to start it from five. Condition will be. Sorry, i greater equals to one. And here you need to write i minus. So only this change will print this pattern. Right. Now let's see how. So initially i is five. This time. Check this condition. It is true. Come here. Starting from one. Now check this condition five minus. So i is five. So five minus zero. This loop will not repeat. And we don't require any space because we need spaces in this way. We need spaces in this way zero, one, two, three and four. So we don't require any space. Then come to this loop. I is five. So five into two and minus one nine. So first time it will be nine times. So nine stars. This will complete new line that I minus minus. So now i is four. Check this loop. Five minus four. That is one. So this loop will be one time. So one space is required. Come to this loop. Four into two minus one. So four into two eight minus one seven. So this will be seven times. So we require seven. So this way I hope you understood if we change the outer loop and we keep inner loops as it is, then this group can be implemented. So I hope with these explanation, you understood how we can print these patterns with alcox C program. If you want to watch more programming related videos, you can open my channel, go to playlist. So there you will find more than 1000 videos. So you can watch them. Those are related to various programming languages. And I hope you understood whatever I explained in this video. Thank you for watching this video.