Advertisement
Divyansh_Chourey

matrix multiplication

Apr 17th, 2024
558
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.84 KB | None | 0 0
  1. /*Please consider saving the code of 'array function'(from my pastebin) as 'functions.c' in the same folder as the following code is saved*/
  2. #include<stdio.h>
  3. #include"functions.c"
  4.  
  5. int main(){
  6.     int order;
  7.     int sum;
  8.     printf("Only square matrices are allowed\nWhat is the order of matrices: ");
  9.     scanf("%d", &order);
  10.    
  11.     int mat1[order][order];
  12.     input_matrix(order, mat1);
  13.     printf("Matrix 1 is:\n");
  14.     display_matrix(order, mat1);
  15.    
  16.     int mat2[order][order];
  17.     input_matrix(order, mat2);
  18.     printf("Matrix 2 is:\n");
  19.     display_matrix(order, mat2);
  20.    
  21.     int mat_result[order][order];
  22.     for(int i=0; i<order; i++){
  23.         for(int j=0; j<order; j++){
  24.             sum=0;
  25.             for(int k=0; k<order; k++){
  26.                 sum = sum+mat1[i][k]*mat2[k][j];
  27.             }
  28.             mat_result[i][j] = sum;
  29.         }
  30.     }
  31.     printf("Multiplication is: \n");
  32.     display_matrix(order, mat_result);
  33.     return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement