To calculate product of two arrays (Matrix Multiplication).





#include
#include

main()
{
int a[5][5],b[5][5],c[5][5];
int i,j,k;
int r1,c1,r2,c2;
clrscr();
printf("Input size of first array");
scanf("%d%d",&r1,&c1);
printf("Input size of second array");
scanf("%d%d",&r2,&c2);
if(c1==r2)
{
printf("\nInput %d elements of first array",r1*c1);
for(i=0;ifor(j=0;jscanf("%d",&a[i][j]);
printf("\nInput %d elements of first array",r1*c1);
for(i=0;ifor(j=0;jscanf("%d",&b[i][j]);
clrscr();
printf("\nEntered first array is \n");
for(i=0;i{
for(j=0;j{
printf("%d",&a[i][j]);
}
printf("\n");
}
printf("\nEntered second array is \n");
for(i=0;i{
for(j=0;j{
printf("%d ",b[i][j]);
}
printf("\n");
}
printf("\nProduct of above arrays is\n");
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("%d ",c[i][j]);
}
printf("\n");
}
}
else
printf("\nWrong dimensions, not suitable for product ...");
}

4 comments:

  1. halo sir nice content.would you like communicate with me by blog.mutual follow the blog

    ReplyDelete
  2. hello sir can u please post the same program using pointers?

    ReplyDelete