 Hello friends, I am Sanjay Phukta. I welcome you on Sanjay Phukta Tech School. In this video, I am going to explain how you can convert matrix multiplication algorithm with C language code. So we are going to implement matrix multiplication algorithm with the help of C language. So I am going to write a function for that. So let's say the name of function is matrix multiplication. Its vector type is Y. It will be receiving 3 matrix as input. So let's say the dimension of force matrix is 2 by 3. The dimension of second matrix will be 3 by 4. And dimension of third matrix will be 2 by 4. Then R1 will be number of rows in force matrix. Then C1 column in force matrix. Then R2 and then C. So these all parameters we require to implement this function. Now I am delivering 3 variables IJK so that we can implement 3 different loops because in matrix multiplication, A loops are required. So here you can see A matrix is having this dimension, B matrix is having this dimension. So 2 by 3 and 3 by 4. So rather than the implement matrix multiplication, we need to apply a condition to check these 2 variables. So this is R1, this is C1, this is R2, this is C2. So we need to check C1 with R2. If both are equal, then only matrix multiplication can perform otherwise. So first of all I am writing this condition. If C1 is not equal to R2, so we can write a print test statement, multiplication not possible. And here we can write return. So return will be fabricating execution of this function. So this way we added a check so that we can check whether this function will be possible or not. So C matrix dimension will be 2 by 4 that will be stored in the result. That depends upon these values. No other column. So here you can see we are having 3rd parameter as 2 by 4. So these matrix we are passing through main function. So as per the requirements, we need to create first code setting matrix and then you can create third matrix. So we need to reduce this logic and if you are passing your values as per this logic then your matrix multiplication will be performed otherwise. Now after this I can apply a combination of 3 basket loops so that matrix multiplication can be performed. So I hope you already gone through the algorithm implementation of matrix multiplication. If not you can go to description of this video. So you will find link of a playlist that is beta structure and algorithm preview scene. So in that playlist you can find how we can write algorithm for matrix multiplication. So if you want that algorithm then you will be understanding this implementation in C easy. And also I will be explaining like how this matrix multiplication performs. So first let me write the code then we will discuss the logic. So here first loop will repeat 2 times and then 2 first matrix goes then second loop it will repeat column times of second matrix. So inside this loop I am initializing ij index of 3 matrix with 0 and after that I am writing her loop that is for k equals to 0. Now for this k we can use either C1 or R2 so I am using C1 and I will tell you why we can put C1 or R2. I will be implementing matrix drawing then you will be understanding how it will be performed. So now C of ij equals to C of ij plus A of ij into B of k and then we can close all these loops and this matrix multiplication function. So this is the logic that is implemented in front of you. Now we can have matrix. So this is A matrix whose dimension is 2 by 3 so 2 goes in 3 columns. This is D matrix whose dimension is 3 by 4 so 3 rows and 4 columns. These are indexes and let's say these are values and dimension of A and B are mentioned here 2 3 so its dimension is 2 3 and its dimension is 3 4. So we already checked this C1 and R2 both are equal so multiplication will be performed. So what we need to do we need to multiply this row with this column first then this column then this column and then this column. So 4 times multiplication will be done and every time you can see we need to multiply these digits. So 3 digits are available in row and 3 digits are available in column that is accessible to this tree. And this tree is stored in C1 and R2 so that's why we can use either C1 or R2. So tree root will always be A matrix. Now let's say this is your C matrix and its dimension will be this 2 by 4. So now starting from here i is 0 so let's say this is value of i then we will move to J root that is also 0. Then we will assign 0 to C ij so ij both are 0 so C ij index will be 0. Then K will be starting from sorry 1 sorry 0 K will be starting from 0 C1 so C1 is 3 so this K root will be repeating 3 times. So first time it will be multiplying A ij and P kj so here you can see all values are 0 so A 0 0 will be multiplying with B 0 0. So A 0 0 is this B 0 0 is this so 1 into 1 1 that will be added to C ij that is also 0 0 0 so this will be 1. Now K will be incrementing so K is 1 so here you can see A i k so this will be 1 B kj so this will be 1 so 0 1 for A 1 0 for B so A 0 1 is this B 1 0 is this. So 2 will be multiplying 5 so 5 into 10 plus 1 so here also you can see this is still C ij so ij both are 0 0 so C 0 0 index will be adding 0. Next time K will be incrementing so K is 2 now so here you can see A i k so K is 2 B kj so K is 2 so this is the value of indexes A 0 2 and B 2 0 so A 0 2 is this and B 2 0 is this. So 3 will be multiplying with 9 right 27 plus 11 so it will be 13 so 3 times K 2 will be it now it will be calculated and J will be incrementing so J will be 1 and K will again start from 0 and I is still 0. So this first row will be multiplying with this second row and its result will be this row right again this row will be multiplying with third row result will be stored here then again this row will be multiplying with fourth row. So this way you can see this row is multiplying with all four columns and four different results will be available here then same will happen with this row this row will be multiplied with all four columns and four different values will be available here. So all these values are available in two C matrix so whenever this function will be complicated so the result will be available in two C matrix so you will be calling this function from main and will be passing these parameters so you will be receiving input of K and B from Z and the output of C that is multiplication of matrix will be a one through this function. So whenever you will be calling this function into main so main will be having updated value of C automatically after completion of execution of this function right so you can very quickly print the value of C into main function after completion of this function and you will be having the output as matrix multiplication. So I hope with this explanation you understood how we can implement matrix multiplication algorithm into C language right and if you want to watch both playlists those are related to algorithm and the implementation using C language so you can find their links in the description of this video you can follow that so that you can learn data structure in a well arranged manner. I hope you understood whatever I explained in this video thank you for watching this video.