100% found this document useful (1 vote)
3K views5 pages

Program 5: Implement Matrix Multiplication and Validate The Rules of Multiplication. Algorithm

The document describes a program to implement matrix multiplication. It includes an algorithm with 9 steps to read in two matrices, check that their orders allow multiplication, initialize a result matrix, and calculate the product by iterating through the matrices and summing the multiplied elements. The program code implements this algorithm by defining three matrices, reading in their orders and elements, checking if multiplication is possible, initializing the result to 0, iterating through nested loops to calculate and save the product to the result matrix, and printing the result.

Uploaded by

sufyan shaik
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
3K views5 pages

Program 5: Implement Matrix Multiplication and Validate The Rules of Multiplication. Algorithm

The document describes a program to implement matrix multiplication. It includes an algorithm with 9 steps to read in two matrices, check that their orders allow multiplication, initialize a result matrix, and calculate the product by iterating through the matrices and summing the multiplied elements. The program code implements this algorithm by defining three matrices, reading in their orders and elements, checking if multiplication is possible, initializing the result to 0, iterating through nested loops to calculate and save the product to the result matrix, and printing the result.

Uploaded by

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

SUB CODE: 21CPL17/27

Program 5 : Implement Matrix multiplication and validate the rules of multiplication.

ALGORITHM:

Step 1:start

Step 2:[Read the order of both matrices M,N,P,Q]

Step 3: check for i=0 to M and j=0 to N for the matrix A,read A[i][j]

Step 4:Check for i=0to P and j=0 to Q for matrix B read B[i][j]

Step 5:if(N=P) then only multiplication is possible then go to step 6 otherwise


go
to step 7

Step 6: intialy set matrix C[i][j] as 0


For k=0 to n
C[i][j]=C[i][j]+A[i][k]*B[i][k] go to step 8

Step 7:multiplication is not possible

Step 8:prints the multiplication of two matrix

Step 9:stop

GNDEC/CPL
SUB CODE: 21CPL17/27

FLOWCHART:

GNDEC/CPL
SUB CODE: 21CPL17/27

GNDEC/CPL
SUB CODE: 21CPL17/27

PROGRAM:

#include<stdio.h>
#include<conio.h>
main()
{
int a[20][20],b[20][20],c[20][20];
int m,n,p,q,i,j,k;
clrscr();
printf("enter rows and columns of matrix a\n");
scanf("%d%d",&m,&n);
printf("enter rows and columns of matrix b\n");
scanf("%d%d",&p,&q);
if(n!=p)
{
printf("matrix multiplication not possible\n");
return 0;
}
printf("enter elements of matrix a\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("enter 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<p;i++)
{
for(j=0;j<q;j++)
{
c[i][j]=0;
for(k=0;k<n;k++)
{
c[i][j]=c[i][j]+a[i][k]*b[k][j];
}

GNDEC/CPL
SUB CODE: 21CPL17/27

}
}
printf("product of two matrices is\n");
for(i=0;i<m;i++)
{
for(j=0;j<q;j++)
{
printf("%d\n",c[i][j]);
}
}
getch();
}

GNDEC/CPL

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