 Hello friends, I am Sanjay Gupta. I welcome you on Sanjay Gupta Tech School. In this video, I'm going to explain how you can print transpose of a matrix with the help of 2D array in C language. Before start, I just want to share one information. If you go to detail or description of this video, you will find links of various playlists related to C language. So you can follow them. Now, first I'm going to tell you how we calculate transpose then I will be implementing the program. So, suppose there is a matrix whose dimension is 3 by 4, 3 rows and 4 columns. So these are the row indexes. These are column indexes. And let's say these are the values. So these 12 elements are available in this matrix. Now, if you want to print transpose of a particular matrix, then you need to convert all the rows into columns or you can say you need to convert all the columns into rows. So the transpose of this matrix will be 159. So here you can see 159 are available in a column and the output will be having these values in a row. 10, 2, 6, 10, 3, 7, 11 and 4, 8, 12. So this will be the output. So here you can say transpose of this particular matrix is this. So now I'm going to write a C program so that you will understand how we can perform this option. So here you can see I have declared a 2D array whose dimension is 3, 4. So 3 rows and 4 columns. Now I'm writing a printf which will display a message and 3 by 4 matrix to receive input from user. So here I'm going to implement this loop. So first loop will repeat row times and second loop. Second loop will repeat column times. So first is maintaining through i variable and second loop is maintaining through j variable. So here I'm putting a scanf which will read all the elements from user. So these are simple statements which are used whenever you want to read 2D array from user. Now after this, I'm going to write those statements through which we can print transpose of a matrix. So here I'm putting a printf which will display this message transpose on output screen and by following the statement the digits will be displayed. So now I am going to implement first loop. So see carefully. So here I have mentioned condition as i less than 4. But while I read the values so I put 3 here. So I'm changing row and column values for loop rotation. So I'm going to explain this as well. Here I'm putting j less than 3. Right now I'm going to use printf person be then backslash t backslash t because I want to put some space between two digits and then a of j i. So this is also very important here I'm putting a of j i so first indexes provided through j variable and second is provided through i variable. Now I'm closing this loop. So in a loop is closed then for new line backslash n and then I'm closing outer loop and then main function. So now I'm going to iterate this logic so that you will get to know how it is working for this matrix. So here you can see dimension is three by four. So we have three by four matrix. Now if I start rotation from here so initially I is zero. So initially I is zero. So here I'm writing I as zero then we will move here that is j equals to zero. And if you see this loop, so this loop will repeat three times because condition is j less than three. So this loop will repeat three times. So first time the indexes will be zero zero those will be printed then only j is implemented. So next time value of j will be one. So here index will be one zero. So here you can see zero zero is having one. So one will be printed then one zero one zero position is having five. So here five will be printed. So printing will be done row wise because this printer is not having any backslash n. Then after printing second value j will be increased again. So now its value is two. So next index will be two zero. So an output screen two zero will be printed. So here you can see in this matrix it is here but while printing this this nine will be available here. So it means first column is printed as first row for output. Now this loop will terminate new line will be there then I will be incremented. So I is now one and j will again start from zero j will again start from zero and again it will iterate three times. So here you can see j will remain same but I is now one. So these indexes will be printed. So first index is zero one. So here you can see zero one is two. So two is printed here then next is one one. So one one is fixed. So it is printed here then two one it is 10 and it is printed here. So this way you can see the input matrix columns are printed as rows in output matrix. So with this logic you can print transpose of a particular matrix. You need to remember that if dimension is this three by four. So while reading row will be here and column will be here but while printing column value will be here and row value will be here. And you need to put a ji and here we are putting a i so these changes you need to and in case if your matrix is this three by three. No column both have same size. So then you can put three three here you can put three three here but you need to put ji as it right. So this way I hope you understood how we can print transpose of a matrix with the help of C language. I hope you understood whatever I explained in this video. If you want to watch more programming related videos you can open my channel go to playlist. So there you will be having variety of programs and also you can go to detail or description of this video. So where you will find links of various playlist related to C program. So follow them and thank you for watching this video.