C Program For Matrix Multiplication

#include<stdio.h>
#include<conio.h>
void main()
{
int a[10][10],b[10][10],c[10][10],m,n,o,p,i,j,k;
clrscr();
printf(" rows and col's of 1st matrix: ");
scanf("%d%d",&m,&n);
printf(" rows and col's of 2st matrix: ");
scanf("%d%d",&o,&p);
if(n!=o)
printf("\nmultiplication is not possible\n");
else
{
printf("enter  %d * %d elements of 1st matrix: ",m,n);
for(i=0;i<m;i++)
{
 for(j=0;j<n;j++)
 {
 scanf("%d",&a[i][j]);
 }
}
printf("enter  %d * %d elements of 2nd matrix: ",o,p);
for(i=0;i<o;i++)
{
 for(j=0;j<p;j++)
 {
 scanf("%d",&b[i][j]);
 }
}

for(i=0;i<m;i++)
{
 for(j=0;j<p;j++)
 {
 c[i][j]=0;
 for(k=0;k<o;k++)
        c[i][j]=c[i][j]+a[i][k]*b[k][j];
 }
}
 printf("Resultant matrix is: \n");
 for(i=0;i<m;i++)
 {
  for(j=0;j<p;j++)
  {
   printf("%4d",c[i][j]);
  }
  printf("\n");
 }
}
getch();
}
Bhanu Namikaze

Bhanu Namikaze is an Ethical Hacker, Security Analyst, Blogger, Web Developer and a Mechanical Engineer. He Enjoys writing articles, Blogging, Debugging Errors and Capture the Flags. Enjoy Learning; There is Nothing Like Absolute Defeat - Try and try until you Succeed.

No comments:

Post a Comment