Advertisement
semsem_elazazy

Untitled

Dec 24th, 2021
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.19 KB | None | 0 0
  1. #include<stdio.h>
  2. int main(){
  3.  int a[5][5],b[5][5],c[5][5],i,j,k,sum=0,m,n,o,p;
  4. printf("\nEnter the row and column of first matrix");
  5. scanf("%d %d",&m,&n);
  6. printf("\nEnter the row and column of second matrix");
  7. scanf("%d %d",&o,&p);
  8.  if(n!=o){
  9.  printf("Matrix mutiplication is not possible");
  10.  printf("\nColumn of first matrix must be same as row of second matrix");
  11. }
  12.  else{
  13.  printf("\nEnter the First matrix->");
  14. for(i=0;i<m;i++)
  15.  for(j=0;j<n;j++)
  16.  scanf("%d",&a[i][j]);
  17.  printf("\nEnter the Second matrix->");
  18. for(i=0;i<o;i++)
  19.  for(j=0;j<p;j++)
  20.  scanf("%d",&b[i][j]);
  21.  
  22.  printf("\nThe First matrix is\n");
  23.  for(i=0;i<m;i++){
  24.  printf("\n");
  25.  for(j=0;j<n;j++){
  26.  printf("%d\t",a[i][j]);
  27.  }
  28.  }
  29. printf("\nThe Second matrix is\n");
  30.  for(i=0;i<o;i++){
  31.  printf("\n");
  32.  for(j=0;j<p;j++){
  33.  printf("%d\t",b[i][j]);
  34.  }
  35.  }
  36.  for(i=0;i<m;i++)
  37.  for(j=0;j<p;j++)
  38.  c[i][j]=0;
  39.  for(i=0;i<m;i++){ //row of first matrix
  40.  for(j=0;j<p;j++){ //column of second matrix
  41.  sum=0;
  42.  for(k=0;k<n;k++)
  43.  sum=sum+a[i][k]*b[k][j];
  44.  c[i][j]=sum;
  45.  }
  46.  }
  47. }
  48. printf("\nThe multiplication of two matrix is\n");
  49.  for(i=0;i<m;i++){
  50.  printf("\n");
  51.  for(j=0;j<p;j++){
  52.  printf("%d\t",c[i][j]);
  53.  }
  54. }
  55.  return 0;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement