 Hello friends, I am Sanjay Gupta. In this video, I am going to demonstrate you how you can print this pattern using C program. Before starting, you can note my information. You can follow or subscribe my YouTube channel through this link that is youtube.com slash sanjaygupta underscore tech school. You can download my app Techimus that is available on Google Play. Now you can see this pattern here diagonal values are 1 and remaining values are 0 and this is 5 by 5 matrix. So I am using printf statement which will display enter how many rows you want to print. So here the number of rows will be equals to number of columns. If you are entering number of rows as 10, so columns will also be 10. So you have to print 10 by 10 matrix. So I have just read number of rows because number of columns will be same. Now I am implementing first loop starting from 1 and it will repeat n times. Inside this loop, this loop will provide which number of row we are printing. For columns, I am implementing another loop which is starting from 1. It will also repeat n times. Because each row is containing n number of columns. Here I have to implement a if condition i double equals to j. So if i and j both are equal, then it means they are pointing to the diagonal position. So here I have to print 1 else I have to print 0. After termination of j loop for line change, I have to use slash n inside printf. So this is the complete code which will display above mentioned pattern on console. So you can see there are two loops. First is for number of rows and second is for number of columns. Suppose value of i is 1 and n is 5. So this j loop will also repeat 5 times. So initially it is also 1. So if condition will be true because i and j both are 1. So 1 will be displayed. Then j will be incremented. Its value will become 2. But i will remain 1. So 1 double equals to 2. It will become false. So 0 will be printed. So this way this j loop will repeat 5 times and remaining zeros will be displayed. Then new line will be displayed on console. Then i plus plus so i will become 2. Again j will start from 1. So first time if condition will be false. So 0 will be printed. Then second time when j will become 2. So i and j both will be 2. So this condition will be true and 1 will be displayed on console. So if condition is true then only 1 will be displayed otherwise 0 will be displayed on console. Now i am executing this code so that you can see whether it is displaying on console or not. You can compare the output with the pattern. It is printing as it is available here in front of you. So using these nested loop combination which are repeating same number of times you can print above mentioned pattern on console. Now if you want to change the digits. If you want to print 0 on diagonal positions and 1 on other positions you can simply change these values. I have changed 0 and 1 in if condition. Again i am executing this code. I am entering number of rows as 5. You can see the output. This time diagonally it is printing 0 and other elements are 1. So i hope you have understood how you can print this pattern with the help of C program. If you want to watch more programming related videos you can follow my youtube channel that is youtube.com slash sanjaygupta underscore tech school. Thank you for watching this video.