C Program to multiply two matrix
yet to be updated
Try your Solution
Strongly recommended to Solve it on your own, Don't directly go to the solution given below.
#include<stdio.h>
int main()
{
//write your code here
}
Program or Solution
#include <stdio.h>
int main()
{
int r1, c1, r2, c2, i, j, k;
printf("Enter rows and column for first matrix: ");
scanf("%d %d", &r1, &c1);
printf("\nEnter rows and column for second matrix: ");
scanf("%d %d",&r2, &c2);
if (c1 != r2)
{
printf("\ncolumn of first matrix not equal to row of second.\n");
}
else
{
int a[r1][c1],b[r2][c2],result[r1][c2];
printf("\nEnter elements of matrix 1:\n");
for(i=0; i<r1; ++i)
for(j=0; j<c1; ++j)
{
scanf("%d", &a[i][j]);
}
printf("\nEnter elements of matrix 2:\n");
for(i=0; i<r2; ++i)
for(j=0; j<c2; ++j)
{
scanf("%d",&b[i][j]);
}
for(i=0; i<r1; ++i)
for(j=0; j<c2; ++j)
{
result[i][j] = 0;
}
for(i=0; i<r1; ++i)
for(j=0; j<c2; ++j)
for(k=0; k<c1; ++k)
{
result[i][j]+=a[i][k]*b[k][j];
}
printf("\nOutput Matrix:\n");
for(i=0; i<r1; ++i)
for(j=0; j<c2; ++j)
{
printf("%d ", result[i][j]);
if(j == c2-1)
printf("\n\n");
}
}
return 0;
}
Program Explanation
yet to be updatedComments
Related Programs
- C Program to get and print the array elements
- C Program to find the sum of array elements
- C Program to find the sum and average of array Elements
- C Program to Search an Element in an array
- C Program to find Largest element in the array
- C Program to find Smallest element in the array
- C Program to print all the numbers which are less than given key element from a given array.
- C Program to find Second Largest element in the array
- C Program to find Second smallest element in the array
- C Program to delete an element in an array
- C Program to Reverse the Elements in array
- C Program to reverse the first half of array elements
- C Program to reverse the second half of array elements
- C Program to Sort the Elements in ascending order
- C Program to Sort the Elements in descending order
- C Program to sort half of the Array elements in ascending order and next half in descending order
- C Program to Merging two arrays
- C Program to replace every element with the greatest element on right side
- C Program to perform circular Array Rotation
- C Program to add two matrix
- C Program to transpose the Matrix
coming Soon
coming Soon