A program for Multiplication of square matrices

#include<stdio.h>
#include<conio.h>
void main()
{
int a[10][10],b[10][10],c[10][10],i,j,k,m,n,p,q;
clrscr();
printf("Enter the order of first matrix:");
scanf(" %d %d",&m,&n);
printf("Enter the order of second matrix:");
scanf("%d %d",&p,&q);
if((m==n)&&(n==p))
{
printf("Enter first matrix elements:\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
scanf("%d",&a[i][j]);
}
printf("Enter second matrix elements:\n");
for(i=0;i<p;i++)
{
for(j=0;j<q;j++)
scanf("%d",&b[i][j]);
}
for(i=0;i<m;i++)
{
for(j=0;j<q;j++)
{
c[i][j]=0;
for(k=0;k<n;k++)
c[i][j]=c[i][j]+(a[i][k]*b[k][j]);
}
}
printf("Resultant matrix elements:\n");
for(i=0;i<m;i++)
{
for(j=0;j<q;j++)
{
printf(" %d ",c[i][j]);
}
printf(" \n");
}
}
else
printf("\n Not a Square Matrix and Matrix multiplication is not possible ");
getch();
}

No comments:

Post a Comment

Copyright © EduRAR @ www.edurar.blogspot.in