Saturday, December 5, 2009

MATRIX MULTIPLICATION

Matrix multiplication program is used for multiply two matrix.The different two rows and columns matrix multiplication.

Example 3X3 Matrix multiplication program in C language is given below:

void main()
{
int a[10][10],b[10][10],c[10][10],i,j,k,m,n,p,q;
clrscr();
printf("Enter The Rows And Cloumns And Of The First Matrix:");
scanf("%d %d",&m,&n);
printf("\nEnter The Rows And Cloumns And Of The Second Matrix:");
scanf("%d %d",&p,&q);
printf("\nEnter Elements Of The First Matrix:\n");
for(i=0;i<>
{
for(j=0;j<>
scanf("%d",&a[i][j]);
}

printf("\nEnter Elements Of The Second Matrix:\n");
for(i=0;i<>
{
for(j=0;j<>
scanf("%d",&b[i][j]);
}
printf("The First Matrix Is:\n");
for(i=0;i<>
{
for(j=0;j<>
printf(" %d ",a[i][j]); //print the first matrix
printf("\n");
}
printf("The Second Matrix Is:\n");
for(i=0;i<>
{
for(j=0;j<>
printf(" %d ",b[i][j]);
printf("\n");
}
if(n!=p)
{
printf("Aborting!!!!!!/nMultiplication Of The Above Matrices Not Possible.");
exit(0);
}
else
{
for(i=0;i<>
{
for(j=0;j<>
{
c[i][j] = 0;
for(k=0;k<>
{
c[i][j] = c[i][j] + a[i][k] * b[k][j];
}
}
}
printf("\nMultiplication Of The Above Two Matrices Are:\n\n");
for(i=0;i<>
{
for(j=0;j<>
{
printf(" %d ",c[i][j]);
}
printf("\n");
}
}
getch();
}

0 comments:

Post a Comment

  © Blogger template Coozie by Ourblogtemplates.com 2008

Back to TOP