C Programs

Write a C program for matrix multiplication?


/* C program for matrix multiplication */
#include<stdio.h>
#include<conio.h>

#define m 2
#define n 2
#define p 2
#define q 2

int main(){
    int A[m][n],B[p][q],C[m][q],i,j,k,sum;
    clrscr();
    printf("Enter Elements for A matrix :\n");
    for(i=0;i<m;i++){
       for(j=0;j<n;j++){
         scanf("%d",&A[i][j]);
       }
    }
    printf("Enter Elements for B Matrix :\n");
    for(i=0;i<m;i++){
       for(j=0;j<n;j++){
          scanf("%d",&B[i][j]);
       }
    }
    for(i=0;i<m;i++){
        for(j=0;j<q;j++){
      sum = 0;
      for(k=0;k<p;k++){
         sum += A[i][k] * B[k][j] ;
      }
      C[i][j] = sum;
  }
    }
    printf("Required Matrix is :\n");
    for(i=0;i<m;i++){
 for(j=0;j<q;j++){
     printf("%d ",C[i][j]);
 }
 printf("\n");
    }
    getch();
    return 0;
}
www.000webhost.com