0% found this document useful (0 votes)
4 views1 page

L6. Implement Matrix Multiplication and Validate The Rules of Multiplication

The document contains a C program that implements matrix multiplication. It prompts the user to input the dimensions and elements of two matrices, checks if multiplication is possible, and then performs the multiplication if valid. The program outputs the resultant matrix after performing the calculations.

Uploaded by

mohitek894
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views1 page

L6. Implement Matrix Multiplication and Validate The Rules of Multiplication

The document contains a C program that implements matrix multiplication. It prompts the user to input the dimensions and elements of two matrices, checks if multiplication is possible, and then performs the multiplication if valid. The program outputs the resultant matrix after performing the calculations.

Uploaded by

mohitek894
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

L6.

Implement Matrix multiplication and validate the rules of multiplication


/* L6: matrix Multiplication */ printf("B matrix:\n");
#include<stdio.h> for(i = 0; i < p; ++i)
int main() {
{ for(j = 0; j < q; ++j)
int m, n, p, q, a[5][5], b[5][5], c[5][5], i, j, k; printf("%4d",b[i][j]);
printf("Matrix Multiplication: \n"); printf("\n");
printf("Enter order of A matrix: "); }
scanf("%d %d", &m, &n);
/*matrix Multiplication begins*/
printf("Enter order of A matrix: "); for(i = 0; i < m; ++i)
scanf("%d %d" ,&p, &q); for(j = 0; j < q; ++j)
if(n!=p) {
{ c[i][j] = 0;
printf("Matrix multiplication not possible "); for(k = 0; k < n; ++k)
} c[i][j] += a[i][k] * b[k][j];
else }
{
printf("Enter %d elements of Mat A...\n", m*n); printf(" Resultant matrix C:\n");
for(i = 0; i < m; ++i) for(i = 0; i < p; ++i)
for(j = 0; j < n; ++j) {
scanf("%d", &a[i][j]); for(j = 0; j < q; ++j)
printf("%4d",c[i][j]);
printf("Enter %d elements of mat B...\n", p*q); printf("\n");
for(i = 0; i < p; ++i) }
for(j = 0; j < q; ++j) } /* end of else */
scanf("%d", &b[i][j]); } /* end of main */

printf("A matrix:\n");
for(i = 0; i < m; ++i)
{
for(j = 0; j < n; ++j)
printf("%4d",a[i][j]);
printf("\n");
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy