Variables used
i,j -Loop control
m,n,p,q - Row & Column
a,b -Arrays
Program
#include<stdio.h>
main()
{
system("clear");
void mat(int[10][10],int[10][10],int,int,int);
int i,j,m,n,p,q,a[10][10],b[10][10];
printf("Enter The no of rows and column of 1st matrix");
scanf("%d%d",&m,&n);
printf("Enter The no of rows and column of second matrix\n");
scanf("%d%d",&p,&q);
if(n==p)
{
printf("Enter The element of first matrix \n\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
scanf("%d",&a[i][j]);
}
printf("The first matrix is \n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
printf("%d\t",a[i][j]);
printf("\n");
}
printf("Enter The elements of The second metrix\n")
for(i=0;i<p;i++)
{
for(j=0;j<q;j++)
scanf("%d",&b[i][j]);
}
printf("The second matrix is \n");
for(i=0;i<p;i++)
{
for(j=0;j<q;j++)
printf("%d\t",b[i][j]);
printf("\n");
}
mat(a,b,m,n,q);
}
else
printf("Multiplication is not possible\n");
}
void mat(int a[][10],int b[][10],int m,int n,int q)
{
int i,j,k,c[10][10];
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("The product of two matrix\n");
for(i=0;i<m;i++)
{
for(j=0;j<q;j++)
printf("%d\t",c[i][j]);
printf("\n");
}
}
Output
Enter The no of rows and column of 1st matrix 2 2
Enter The no of rows and column of second matrix 2 2
Enter The element of first matrix 2 2 2 2
The first matrix is
2 2
2 2
Enter The elements of The second matrix 2 2 2 2
The second matrix is
2 2
2 2
The product of two matrix
m,n,p,q - Row & Column
a,b -Arrays
Program
#include<stdio.h>
main()
{
system("clear");
void mat(int[10][10],int[10][10],int,int,int);
int i,j,m,n,p,q,a[10][10],b[10][10];
printf("Enter The no of rows and column of 1st matrix");
scanf("%d%d",&m,&n);
printf("Enter The no of rows and column of second matrix\n");
scanf("%d%d",&p,&q);
if(n==p)
{
printf("Enter The element of first matrix \n\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
scanf("%d",&a[i][j]);
}
printf("The first matrix is \n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
printf("%d\t",a[i][j]);
printf("\n");
}
printf("Enter The elements of The second metrix\n")
for(i=0;i<p;i++)
{
for(j=0;j<q;j++)
scanf("%d",&b[i][j]);
}
printf("The second matrix is \n");
for(i=0;i<p;i++)
{
for(j=0;j<q;j++)
printf("%d\t",b[i][j]);
printf("\n");
}
mat(a,b,m,n,q);
}
else
printf("Multiplication is not possible\n");
}
void mat(int a[][10],int b[][10],int m,int n,int q)
{
int i,j,k,c[10][10];
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("The product of two matrix\n");
for(i=0;i<m;i++)
{
for(j=0;j<q;j++)
printf("%d\t",c[i][j]);
printf("\n");
}
}
Output
Enter The no of rows and column of 1st matrix 2 2
Enter The no of rows and column of second matrix 2 2
Enter The element of first matrix 2 2 2 2
The first matrix is
2 2
2 2
Enter The elements of The second matrix 2 2 2 2
The second matrix is
2 2
2 2
The product of two matrix
No comments:
Post a Comment