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
to find the closest pair
I have written a pro*C program to fetch data from the cursor. where in i have used the concept of BULK FETCH.... each FETCH statement is taking lots of time to fetch specified number of rows at...
What is c preprocessor mean?
Write a code to achieve inter processor communication (mutual exclusion implementation pseudo code)?
1. Write a function to display the sum of two numbers in the following ways: By using (i) pass by value (ii) pass by address a. function with argument and with return value b. function with argument and without return value c. without argument , with return value d. without argument , without return value Note: Use pass by address.
How many levels of pointers can you have?
What is new line escape sequence?
what is event driven software and what is procedural driven software?
Can we add pointers together?
FILE PROGRAMMING
What is the importance of c in your views?
Can static variables be declared in a header file?
What does c in a circle mean?
Why clrscr is used in c?
Explain what are multidimensional arrays?