Showing posts with label Program to multiply two Matrices. Show all posts
Showing posts with label Program to multiply two Matrices. Show all posts

Monday, September 14, 2009

Program to Multiply Two Matrices

#include "stdio.h"


#include "conio.h"

typedef int MATRIX;

void main()

{

MATRIX x[5][5],y[5][5],z[5][5];

int i,j,r,c,k;

clrscr();

do{

printf("\n Enter the no. of rows for two matrices : ");

scanf("%d",&r);

printf("\n Enter the no. of cols for two matrices : ");

scanf("%d",&c);

if(r<=0

c<=0)

printf("\n MATRIX is NOT Possible");

if(r!=c)

printf("\n MULTIPLICATION is not possible");

}while(r<=0

c<=0

r!=c);

printf("\n --**:: FIRST MATRIX ::**--");

for(i=1;i<=r;i++)

{

for(j=1;j<=c;j++)

{

printf("\n Element X(%d,%d) :",i,j);

scanf("%d",&x[i][j]);

}

}

printf("\n --**:: SECOND MATRIX ::**--");

for(i=1;i<=r;i++)

{

for(j=1;j<=c;j++)

{

printf("\n Element Y(%d,%d) :",i,j);

scanf("%d",&y[i][j]);

}

}

for(i=1;i<=r;i++)

{

for(j=1;j<=c;j++)

{

z[i][j]=0;

for(k=1;k<=r;k++)

{

z[i][j]+=x[i][k]*y[k][j];

}

}

}

printf("\n --**:: FIRST MATRIX ::**--");

for(i=1;i<=r;i++)

{

printf("\n");

for(j=1;j<=c;j++)

{

printf("\t%d",x[i][j]);

}

}

printf("\n --**:: SECOND MATRIX ::**--");

for(i=1;i<=r;i++)

{

printf("\n");

for(j=1;j<=c;j++)

{

printf("\t%d",y[i][j]);

}

}

printf("\n --**:: MULTIPLICATION DONE ::**--");

printf("\n Result is : \n");

for(i=1;i<=r;i++)

{

printf("\n");

for(j=1;j<=c;j++)

{

printf("\t%d",z[i][j]);

}

}

getch();

}