 Hello friends. I am Sanjay Gupta. In this video, I am going to demonstrate you how you can swap elements of two matrix in C programming. Before starting, you can note my information. You can follow or subscribe my YouTube channel through the url youtube.com slash sanjaygupta underscore tech school. You can download my programming app TechMS which is available on Google Play. Now first I am going to implement the solution using third variable. So there are two concepts available for slapping using or without using third variable. So first I am implementing the concept of using third variable. So I am including a header file stdio.h. Then I am defining main function. Inside main I am declaring two 2D arrays. A and B. Then a temporary variable T and INJ for loop counter. Now I have to read two matrix first. So I am showing the message enter first matrix using printf on one soul. Then to receive elements, I am implementing nested loops. So first loop is I which will provide row index. Second loop is J which will provide column indexes. Now scanner statement which will read the elements entered by the user in first 2D array. That is A. Now I am copying these instructions and I am pasting. Now I am converting this first into second and here A into B. So this way you can see through these line number 7 to 12 first matrix elements will be received from user. And from line number 13 to 18 through these instructions elements of second matrix will be received from user. Now I have to apply the logic so that I can swap the elements using third variable. So again I am implementing loops. So again I am implementing nested loops. So inside this J loop I have to implement the logic. So I am applying T equals to Aij. Then Aij equals to Bij, Pij equals to T. So this is the first logic which is swapping elements of A and B matrix with the help of temporary variable. Now I have to display the elements again on console. So I am going to display a message. Elements of first matrix. Now for loop. So again I am implementing nested loops so that I can display the results on console. So I am printing A matrix first for completion of J loop. I am going to use slash n because I want to print rows in separate lines. So this will print first matrix. Now I am copying these instructions and in place of first I am using second and in place of A I am typing B. So this way I have implemented the complete code. So now from beginning you can see here first matrix reading instructions are written. Then second matrix reading instructions. Then I have implemented the code for swapping. Then you can see I am printing elements of first matrix and then I am printing elements of second matrix. So this way the complete code is available in front of you. I am executing this code now. Sorry I have forgot to write semicolon here. So it is asking for the elements of first matrix. So I am entering all ones in first matrix. Now it is asking for the second matrix. So here I am entering four at all places. Now you can see the output. Previously first matrix was 111 and now it is 444. Previously second matrix elements was all four. Now it is containing all ones. So this is the swapping of two matrix with the help of using third element or you can say third or temporary variable. Now I am removing this temporary variable without using third variable. So I can remove this D from here and now just I am modifying these three instructions. So I am making these instructions as comment and now I am writing new instructions. So these instructions are aij equals to aij plus bij. Then bij equals to aij minus bij. Then aij equals to aij minus bij. So this way right now I have implemented the code which will swap matrix sorry which will swap elements of two matrices without using third variable. So again I am executing this code. I am entering elements of first matrix all one. I am entering elements of second matrix all four. You can see the result again swap elements are printing first matrix. All elements are four second matrix. All elements are one and previously picture was different. So this way I have implemented both the logics using and without using third variable swapping of two matrix in C programming. I hope you have understood the concept well. If you want to watch more programming related videos you can follow or subscribe my YouTube channel through the URL youtube.com slash sanjaygupta underscore tech school. You can download my programming app TechMills which is available on Google Play. Thank you for watching this video.