to find the program of matrix multiplication using arrays
Answer Posted / mani prakesh
#include<stdio.h>
#include<conio.h>
main()
{
int i,j,r1,c1,r2,c2,m1[2][2],m2[2][2],k,mult[2][2];
printf("Enter rows and columns of first matrix \n");
printf("Again row wise\n");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
scanf("%d",&m1[i][j]);
}
printf("You have entered the first matrix as follows:\n");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
printf("%d\t",m1[i][j]);
printf("\n");
}
printf("Enter rows and columns of Second matrix \n");
printf("Again row wise\n");
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
scanf("%d",&m2[i][j]);
}
printf("You have entered the second matrix as
follows:\n");
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
printf("%d\t",m2[i][j]);
printf("\n");
}
// Matrix Multiplication
if(r2==c1)
{
printf("Now we multiply both the above matrix \n");
printf("The result of the multiplication is as
follows:\n");
/*a11xA11+a12xA21+a13xA31 a11xA12+a12xA22+a13xA32
a11xA13+a12xA23+a13xA33*/
for(i=0;i<r1;i++)
{
for(j=0;j<c2;j++)
{
mult[i][j]=0;
for(k=0;k<r1;k++)
{
mult[i][j]+=m1[i][k]*m2[k][j];
/*mult[0][0]=m1[0][0]*m2[0][0]+m1[0][1]*m2[1][0]+m1[0][2]*m2[2][0];*/
}
printf("%d\t",mult[i][j]);
}
printf("\n");
}
}
else
{
printf("Matrix multiplication cannot be done");
}
getch();
}
| Is This Answer Correct ? | 4 Yes | 1 No |
Post New Answer View All Answers
How can I handle floating-point exceptions gracefully?
What does *p++ do? What does it point to?
#include main() { enum _tag{ left=10, right, front=100, back}; printf("left is %d, right is %d, front is %d, back is %d",left,right,front,back); }
How can I make it pause before closing the program output window?
What is #include cctype?
What is cohesion in c?
Function which gives a pointer to a binary trees const an integer value at each code, return function of all the nodes in binary tree.?
Given two strings S1 and S2. Delete from S2 all those characters which occur in S1 also and finally create a clean S2 with the relevant characters deleted.
How can I remove the trailing spaces from a string?
What are the features of c languages?
Difference between constant pointer and pointer to a constant.
Ow can I insert or delete a line (or record) in the middle of a file?
how many types of operators are include in c language a) 4 b) 6 c) 8 d) 12
Explain what are compound statements?
What is a double c?