#include<stdio.h>
#include<stdlib.h>
int main()
{
int **p,**q,**s;
int m1,m2,n1,n2,i,j,k=0,sum;
printf("enter oreder of 1st matrix:");
scanf("%d%d",&m1,&n1);
printf("Enter order of 2nd matrix:");
scanf("%d%d",&m2,&n2);
if(m1!=n2)
printf("Multiplication not possible.");
else
{
printf("Enter elements of 1st matrix:");
p=malloc(m1*sizeof(int*));
for(i=0;i<m1;i++)
p[i]=malloc(n1*sizeof(int));
for(i=0;i<m1;i++)
for(j=0;j<n1;j++)
scanf("%d",&p[i][j]);
printf("Enter elements of 2nd matrix:");
q=malloc(m2*sizeof(int*));
for(i=0;i<m2;i++)
q[i]=malloc(m2*sizeof(int));
for(i=0;i<m2;i++)
for(j=0;j<n2;j++)
scanf("%d",&q[i][j]);
printf("product is\n");
s=malloc(m1*sizeof(int*));
for(i=0;i<m1;i++)
s[i]=malloc(n2*sizeof(int));
for(i=0;i<m1;i++)
{
for(j=0;j<n2;j++)
{
sum=0;
for(k=0;k<m1;k++)
{
sum=sum+p[i][k]*q[k][j];
}
s[i][j]=sum;
printf("%d ",s[i][j]);
}
printf("\n");
}
}
}
#include<stdlib.h>
int main()
{
int **p,**q,**s;
int m1,m2,n1,n2,i,j,k=0,sum;
printf("enter oreder of 1st matrix:");
scanf("%d%d",&m1,&n1);
printf("Enter order of 2nd matrix:");
scanf("%d%d",&m2,&n2);
if(m1!=n2)
printf("Multiplication not possible.");
else
{
printf("Enter elements of 1st matrix:");
p=malloc(m1*sizeof(int*));
for(i=0;i<m1;i++)
p[i]=malloc(n1*sizeof(int));
for(i=0;i<m1;i++)
for(j=0;j<n1;j++)
scanf("%d",&p[i][j]);
printf("Enter elements of 2nd matrix:");
q=malloc(m2*sizeof(int*));
for(i=0;i<m2;i++)
q[i]=malloc(m2*sizeof(int));
for(i=0;i<m2;i++)
for(j=0;j<n2;j++)
scanf("%d",&q[i][j]);
printf("product is\n");
s=malloc(m1*sizeof(int*));
for(i=0;i<m1;i++)
s[i]=malloc(n2*sizeof(int));
for(i=0;i<m1;i++)
{
for(j=0;j<n2;j++)
{
sum=0;
for(k=0;k<m1;k++)
{
sum=sum+p[i][k]*q[k][j];
}
s[i][j]=sum;
printf("%d ",s[i][j]);
}
printf("\n");
}
}
}
No comments:
Post a Comment