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


Please Help Members By Posting Answers For Below Questions

What is hashing in c language?

620


What is #include cctype?

582


What is a macro, and explain how do you use it?

633


Do you have any idea how to compare array with pointer in c?

611


Describe the header file and its usage in c programming?

626






Create a structure to specify data on students as given below: Roll number, Name, Department, Course, and Year of joining. Assume that there are not more than 450 students in the collage. (a) Write a function to print the names of all students who joined in the last 3 years. (b) Write a function to print the data of a student whose roll numbers are divisible by 4.

611


Explain can static variables be declared in a header file?

686


What is the difference between c and python?

590


You are to write your own versions of strcpy() and strlen (). Call them mystrcpy() and mystrlen(). Write them first as code within main(), not as functions, then, convert them to functions. You will pass two arrays to the function in the case of mystrcpy(), the source and target array.

1787


What is the use of function overloading in C?

687


What is the use of a semicolon (;) at the end of every program statement?

784


Is c language still used?

540


Is c is a middle level language?

602


What are the c keywords?

756


What are external variables in c?

552