CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com

# Thread: How do I find the product of two rectangular matrices in C Matrix Multiplication?

1. ## How do I find the product of two rectangular matrices in C Matrix Multiplication?

Wanted to understand how this works, need some help on this.  Reply With Quote

2. Junior Member Join Date
Sep 2021
Location
India
Posts
5

## Re: How do I find the product of two rectangular matrices in C Matrix Multiplication? Originally Posted by Soham1087 Wanted to understand how this works, need some help on this.
Here is one example program:

Code:
```#include<stdio.h>
int main(){
int m, n, p, q, i, j, k;
int a, b, res;

printf("Enter the order of first matrix\n");
scanf("%d%d", &m, &n);
printf("Enter the order of second matrix\n");
scanf("%d%d", &p, &q);

if(n!=p){
printf("Matrix is incompatible for multiplication\n");
}
else{
printf("Enter the elements of Matrix-A:\n");
for(i=0;i<m;i++){
for(j=0;j<n;j++){
scanf("%d",&a[i][j]);
}
}

printf("Enter the elements of Matrix-B:\n");
for(i=0;i<p;i++){
for(j=0;j<q;j++){
scanf("%d",&b[i][j]);
}
}

for(i=0;i<m;i++){
for(j=0;j<q;j++){
res[i][j]=0;
for(k=0;k<p;k++){
res[i][j]+=a[i][k]*b[k][j];
}
}
}

printf("The product of the two matrices is:-\n");

for(i=0;i<m;i++){
for(j=0;j<q;j++){
printf("%d\t", res[i][j]);
}
printf("\n");
}
}

return 0;
}```
Read this article on Scaler Topics, it will clear your doubts. Thanks me later!
Last edited by 2kaud; May 30th, 2022 at 11:22 AM. Reason: Changed tags  Reply With Quote

#### Tags for this Thread

c programming #### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

Click Here to Expand Forum to Full Width

Featured