C Program to find multiplication of two matrices write code

itstudentjunction



C Program to find multiplication of two matrices write code


How is matrix mutiplication performed?

Rule: two matrices can only be multiplied if number of columns left matrix A is the equal to the number of rows of the right matrix B.

The result of matrix multiplication is a matrix we get by multiplying the elements within a row from the first matrix by the associated elements within a column from the second matrix and summing the products

eg.

  MAtrix A

a b
c d
MAtrix B

1 2
3 4
Resultant Matrix c

a x 1 + b x 3 , a x 2 + b x 4
c x 1 + d x 3 , c x 2 + d x 4





write a C program to multiply two matrices



write a C program to multiply or find multiplication of two matrices / write a C program to multiply two matrices

#include<stdio.h>
void main(){
int a[5][5],b[5][5],c[5][5],i,j,k,sum=0,m,n,o,p;
printf("\nTo find multiplication or multiply two matrices");
printf("\nEnter the row and column of first matrix");
scanf("%d %d",&m,&n);
printf("\nEnter the row and column of second matrix");
scanf("%d %d",&o,&p);
if(n!=o){
printf("Matrix mutiplication is not possible");
printf("\nColumn of first matrix must be same as row of second matrix");
}
else{
printf("\nEnter the First matrix->");
for(i=0;i<m;i++)
for(j=0;j<n;j++)
scanf("%d",&a[i][j]);
printf("\nEnter the Second matrix->");
for(i=0;i<o;i++)
for(j=0;j<p;j++)
scanf("%d",&b[i][j]);
printf("\nThe First matrix is\n");
for(i=0;i<m;i++){
printf("\n");
for(j=0;j<n;j++){
printf("%d\t",a[i][j]);
}
}
printf("\nThe Second matrix is\n");
for(i=0;i<o;i++){
printf("\n");
for(j=0;j<p;j++){
printf("%d\t",b[i][j]);
}
}
for(i=0;i<m;i++)
for(j=0;j<p;j++)
c[i][j]=0;
for(i=0;i<m;i++){ //row of first matrix
for(j=0;j<p;j++){ //column of second matrix
sum=0;
for(k=0;k<n;k++)
sum=sum+a[i][k]*b[k][j];
c[i][j]=sum;
}
}
}
printf("\nThe multiplication of two matrices is\n");
for(i=0;i<m;i++){
printf("\n");
for(j=0;j<p;j++){
printf("%d\t",c[i][j]);
}
}
}

OUTPUT:

To find multiplication or multiply two matrices

Enter the row and column of first matrix 2 2

Enter the row and column of second matrix 2 2

Enter the First matrix-> 1 1 1 1

Enter the Second matrix-> 1 2 3 4

The First matrix is

1 1
1 1

Enter the Second matrix->

1 2
3 4

The multiplication of two matrices is

4 6
4 6

Other matrices programs:



write a c program for addition of two matrices
write a c pprogram to multiply two matrices

write a c program to find transpose of a matrix

write a c program to find inverse of matrix

write a c program to find lower triangle of a matrix
write a c program to find upper triangle of a matrix
write a c program to implement sparse matrix
write a c program to find addition sparse matrix

write a c program to multiply two sparse matrices


list of c programs




Most popular programs


write a program to find factorial using c
WAP to Calculate Simple Interest
Check for even / odd
perfect or not
sum of two matrices
show amicable pairs
factors of a number using for loop, while
print prime factors using C
convert to uppercase
write a program for prime numbers using for loop
write a program to implement pascal Triangle
check reverse string arrays
find string length strlen
Calculate compound Interest
check armstrong number or not
print prime numbers using while
solve towers of hanoi
Display Floyd’s Triangle
reverse string using pointers
write a program to find a number is prime or not
Show revers number
calculate LCM concatinate strings using arrays
write a program to find palindrome or not
sum of Digits of a number
display transpose matrix
lower triangle
write a C program to multipiy two matrices
write a program to calculate GCD
strong number or not
check substring in c
string length using arrays
string length using pointers
convert to lowercase
WAP to find factors
count no.of digits
show inverse of matrix
show reverse string strrev
write a program to display upper triangle
concatinate strings strCat
convert to lowercase
check for palindrome string
print substring position
compare two strings arrays
compare strings strcmp
find roots of quadriaic expression
show fibonacci numbers
factorial using recurrsion
sum of factorial series
convert decimal to binary
Write a program to print armstrong numbers

decimal to octal
compare strings pointers
decimal to hexadecimal
sum of n numbers
average of n
largest of two
largest of n

write a C program to print pyramid of numbers
strong numbers
perfect numbers using for loop





C Programs Data structures Programs in c Data structures Progra+ms in c++ Unix commands Linux commands C++ programs Data structures Algorithms Java Programs UML Diagrams Assembly Language Programs DBMS j2ee programming