 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 calculate some of the individual row, column and diagonal of a matrix. So I will be implementing this in C language. Now, before starting, I just want to share one information. If you go to the detailed description of this video, you will find links of various playlists related to C programming. So you can follow them as well. Now I am going to write a program first. Then I will be explaining each and every statement with the help of examples so that you can understand how that logic is working. So try to watch the complete video so that you can understand this. So I am starting from main, declaring a 2D array whose dimension is 3 by 3. Then I am declaring some variables. So S1, S2 and S3 and ij, ij is for loop rotation. S1 will store some of rows, S2 will store some of column and S3 will store some of diagonal. Now, one printer statement which will display a message, enter 3 by 3 matrix. So this message will be displayed on the output screen to read values from the user. I need to implement a nested loop. So first loop is for rows and second loop is for columns. And inside second loop I am writing scanup statement. So it will read all the values from the users. And those values will be stored inside aN. Now I am initializing S3 with 0. So S3 will be storing some of diagonal. Then I am starting a loop. So this loop will repeat 3 times. Inside this loop, I am going to initialize two variables, S1 and S2 with 0. So S1 will be having some of individual rows and S2 will be having some of individual columns. Now, one more loop which is also repeating 3 times and this depends upon the column. Inside this loop, I am writing the statements for addition. So here you can see first statement is S1 plus AO5j which will add rows. Then S2 equals to S2 plus AO5j add. So this is for some of columns. Now if Iw equals to j. So S3 equals to S3 plus AO5j. So this statement will be calculated. And after completion of this loop, I am writing one printf. So this printf will print some of rows and columns after completion of this loop. So row equals to percent d, column equals to percent d and S1 comma S2. And after completion of i loop, diagonal sum will be printed with the help of S3. So this is the complete solution. Now I am going to create a 2D array so that you will understand how this logic is working. So let's say this is a 2D array. These are indexes 012, 012 and here I am putting values. So 1, 2, 3, 4, 5, 6, 7, 8, 9. So all 9 values are available here. Now I am going to iterate this loop step by step with the help of this matrix so that you can understand how this logic is working. So let's say I am putting i0, j0, S10, S20 and S30. So I am starting from here. S3 is 0. Then if I go to this step i equals to 0, so i is 0. S1, S2 both are 0. Then I will come here. So j is also 0. So this loop will repeat 3 times. J loop will repeat 3 times. So first time i and j both are same. 0, 0. So a 0, 0 index that is a, sorry that is 1 will be added into S1. So S1 will become 1. Then a ji. So here ij is written and here ji is written. So if we write ij and ji both have same value. So both will return same index values. So ji, do0 will also provide 1. So 1 will be added to S2. So its result will be 1. Then check this condition. i and j both are equal. So 1 will be added to S3 as well. So now we have completed one rotation of j loop. So j will be incremented. So now value of j is 1. So now see carefully. a ij. So i is 0. j is 1. So 0, 1 position is having value as 2. So this 2 will be added to S1. So S1's last value was 1. If we add 1 plus 2, so result will become 3. Now calculate this a ji. So ji is 1. i is 0. So 1, 0 position is having value as 4. So this 4 will be added to S2. So S2 will become 5. And if we check this condition, so you can see this is false because i is 0 and j is 1. So this addition will not be performed. Again j will be incremented. So this time value of j will be 2. Now a ij. So i is 0. j is 2. So 0, 2 position is having 3. So 3 will be added to this. So it will, sorry. 3 will be added to this. So it will become 6. A ji. So j is 2. i is 0. So 2, 0 index is this. So it is 7. So 7 will be added to S2. So it will become 3. And this condition is false. So it will not be calculated. Again, j will be incremented. So j will become 3 and this condition will be false. So when j loop is false, so you can see we can print some of first row and first column. So that will be printed with S1, S2. So on output screen this will be printed. So it equals to 6 and column equals to 12. So first row sum and first column sum. Then i will be incremented. So i will become 1 and S1, S2 will be re-initialized with 0. So S1, S2 will be re-initialized with 0. Only S1, S2 not S3 because S3 is not initialized with 0 inside the loop. It is initialized outside loop as 0. So when both the loop will complete then only value of S3 will be printed. So now i hope you understood S2, S2 or S1 both are having 0 again. So j loop again repeats 3 times. And sum of second row and sum of second column will be available into S1, S2 respectively. They will be printed with this printer. And after completion of both the loops, this S3 will be printed like this. So this way now i hope for second and third row and second and third column you can yourself iterate this logic so that you can understand how it is working. So i hope you understood whatever i explained in this video so that you can understand how we are calculating sum of individual rows, sum of individual columns and sum of final or a 2D edit. If you want to watch more programming related videos you can open my channel, go to playlist. So there are various videos are available and you can also go to the description of this video. So there you will find links of various playlist so you can follow them as well. Thank you for watching this video.