File Name : mulmat.c
#include <stdio.h>
void main()
{
int m,n,p,q,c,d,k,sum=0;
int f[10][10],s[10][10],mul[10][10];
printf("Enter the number of rows and columns of First Matrix\n");
scanf("%d%d",&m,&n);
printf("Enter the elements of First Matrix\n");
for(c=0;c<m;c++)
for(d=0;d<n;d++)
scanf("%d",&f[c][d]);
printf("Enter the number of rows and columns of Second Matrix\n");
scanf("%d%d",&p,&q);
if(n!=p)
printf("The matrices multiplication is not possible.\n");
else
{
printf("Enter the elements of Second Matrix\n");
for(c=0;c<p;c++)
for(d=0;d<q;d++)
scanf("%d",&s[c][d]);
for(c=0;c<m;c++)
{
for(d=0;d<q;d++)
{
for(k=0;k<p;k++)
{
sum=sum+f[c][k]*s[k][d];
}
mul[c][d]=sum;
sum = 0;
}
}
printf("Product of Matrices is:\n");
for(c=0;c<m;c++)
{
for(d=0;d<q;d++)
printf("%d\t", mul[c][d]);
printf("\n");
}
}
}
Output 1:
Enter the number of rows and columns of First Matrix
2
2
Enter the elements of First Matrix
1
2
3
4
Enter the number of rows and columns of Second Matrix
2
2
Enter the elements of Second Matrix
1
2
3
4
Product of Matrices is:
7 10
15 22
Output 2:
Enter the number of rows and columns of First Matrix
2
2
Enter the elements of First Matrix
1
2
3
4
Enter the number of rows and columns of Second Matrix
4
5
The matrices multiplication is not possible.
#include <stdio.h>
void main()
{
int m,n,p,q,c,d,k,sum=0;
int f[10][10],s[10][10],mul[10][10];
printf("Enter the number of rows and columns of First Matrix\n");
scanf("%d%d",&m,&n);
printf("Enter the elements of First Matrix\n");
for(c=0;c<m;c++)
for(d=0;d<n;d++)
scanf("%d",&f[c][d]);
printf("Enter the number of rows and columns of Second Matrix\n");
scanf("%d%d",&p,&q);
if(n!=p)
printf("The matrices multiplication is not possible.\n");
else
{
printf("Enter the elements of Second Matrix\n");
for(c=0;c<p;c++)
for(d=0;d<q;d++)
scanf("%d",&s[c][d]);
for(c=0;c<m;c++)
{
for(d=0;d<q;d++)
{
for(k=0;k<p;k++)
{
sum=sum+f[c][k]*s[k][d];
}
mul[c][d]=sum;
sum = 0;
}
}
printf("Product of Matrices is:\n");
for(c=0;c<m;c++)
{
for(d=0;d<q;d++)
printf("%d\t", mul[c][d]);
printf("\n");
}
}
}
Output 1:
Enter the number of rows and columns of First Matrix
2
2
Enter the elements of First Matrix
1
2
3
4
Enter the number of rows and columns of Second Matrix
2
2
Enter the elements of Second Matrix
1
2
3
4
Product of Matrices is:
7 10
15 22
Output 2:
Enter the number of rows and columns of First Matrix
2
2
Enter the elements of First Matrix
1
2
3
4
Enter the number of rows and columns of Second Matrix
4
5
The matrices multiplication is not possible.
I was taking a gander at some of your posts on this site addition subtraction multiplication and division are all called
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteThank you...Is the program ok?....I welcome any suggestions.
ReplyDelete