OCJP

Multiplication of Matrix

#include<stdio.h>
#include<conio.h>
#define R 3
#define C 3
void main()
{
int mat1[R][C];
int mat2[R][C];
int mat3[R][C];
int i,j,k;
clrscr();
printf("\n enter %d values",R*C);
for(i=0;i<R;i++)
{
for(j=0;j<C;j++)
{
scanf("%d",&mat1[i][j]);
mat3[i][j]=0;
}
}
printf("\n enter %d values",R*C);
for(i=0;i<R;i++)
{
for(j=0;j<C;j++)
{
scanf("\%d",&mat2[i][j]);
}
}

	for(i=0;i<R;i++)
	{
		for(j=0;j<C;j++)
		{
			for(k=0;k<R;k++)
			{
				mat3[i][j] += mat1[i][k]*mat2[k][j];
			}
		}
	}

printf("\n matrix value:\n");
for(i=0;i<R;i++)
{
for(j=0;j<C;j++)
{
printf("%9d",mat3[i][j]);
}
printf("\n");
}
getch();
}

Leave a Reply

Your email address will not be published. Required fields are marked *


Please wait...

Subscribe to our newsletter

Want to be notified when our article is published? Enter your email address and name below to be the first to know.
× How can I help you?
Comodo SSL