 Hello friends, I am Sanjay Gupta. I welcome you on Sanjay Gupta Tech School. In this video, I am going to explain how you can print this pattern. So in this pattern, you can see at diagonal position we have one and remaining positions are zero. So before starting, if you go to detail or description of this video, you will find links of various players. Those are related to my YouTube channel. So you can open them and watch various programming related videos. So now I am going to start solution of this pattern. So this pattern will be implemented with help of nested loop. So we need to implement two loops. One will be controlled in the rows. So here you can see we have five rows. So row one, row two, row three, row four and row five. So when will be on row number one. So here you can see we have five columns. So row one will print five elements, row two will print five elements and so on. So column one, column two, column three, column four and column five. And this is a square matrix where number of rows and columns are same. So if we have square matrix, then only we have title. So rows and columns will be same. Then only you can print this diagonal as one. So now I am going to implement first loop. So it is starting from one, addition is i less than five and then i plus plus. So this loop will repeat five times inside this loop when it will be repeating one time. So inside this loop, I am going to implement one more which will start from one also repeat five times. So this is inner loop. So this one is outer loop and this is inner loop. Now inside this inner loop, I am going to apply if i double equals to j. So when i and j both are equal, it means i is representing row number and j is representing column number. So it both are same. Let's say r1, c1, if they are same, we need to print. Then r2, c2, if they are same, then we need to print one. So whenever value of row and column are same, then only we need to print one otherwise below. So if it is true, then inside printer double quotes, you can print one. Else you can print zero. Right. And then you can close this inner volume. After closing this, you need to print new line character as backslash and then you can close out. So this way the solution of this pattern is implemented. Now I'm explaining its rotation so that you will understand it clearly. So first it will start. So I will be one. Now check the condition of how it is true. Then control will be transferred to this inner loop. So when control is here with j, so j will again start with one and it will repeat five times. So five times this condition will be checked one time it will be true and remaining time it will be false. So j is starting from one. Now see, i and j both are equal. So one will be printed. It means this value is printed. Now j will be incremented. So j is now two. So see when value of i is one, so j is repeating completely five times. So j is two. Again check this condition. So it is true or false. It is false because i is one and j is two. So this time else part will print zero. So this zero will be printed. Again j will be incremented. So this time it is true. So this time it is three. So again condition is false. So it will print zero. Then j will be four. Again condition is false. So it will print zero. Then j will be incremented to five. Again condition is false. So zero will be printed. Then again j will be incremented. So this time you will see this condition is false. So when j is five, so it is true. When j became six, so it is false. So we will come out from this loop and new line character will be printed so that we can print this second row. After this i will be incremented. So this time i will be two. Again control will be transferred here. So j will be initialized by one and again this time it will repeat five times. So first time you can see i is two and j is one. So if it's false, so zero will be printed. Then j will be incremented to two. So this time i and j both are same. So it will print one and then remaining three zeros will be printed because i is two and j will be three, four and five. So this way remaining digits will be printed. And if we see when i is repeating one time, i is repeating one time it means when i is performing one rotation. So j is performing five rotation. So for i one, j is repeating five times. So if i is repeating five times, then j is repeating 25 times. So that's why these digits are printed and at diagonal position we are able to print one and remaining we are able to print zero. And you can change it as well. If you want to print zero on diagonal, so you can put zero here and one here so that diagonal is zero and remaining one will be printed. So i hope you understood how this pattern can be printed with the help of raster loop. If you want to watch more programming related videos, you can open my channel and go to playlists where you will find various programming related videos. So do watch them and thank you for watching this video.