![](/style/images/good.png)
![](/style/images/bad.png)
C++ Program on Multiplication of Two Matrices
source link: https://www.geeksforgeeks.org/videos/cpp-program-on-multiplication-of-two-matrices/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
C++ Program on Multiplication of Two Matrices
- 10 Views
- 13/10/2022
In this video, we will write a C++ program to multiply two matrices.
Multiplication is a fundamental operation in mathematics and computer science. In programming, multiplication is performed using two numbers or variables called operands. Operand means something that is operated upon. An operand can be either a variable or a constant, and a matrix represents the collection of numbers arranged in an order of rows and columns. It is necessary to enclose the elements of a matrix in parentheses or brackets.
For Example:
Input: mat1[m][n] = { {1, 1}, {2, 2} }
mat2[p][q] = { {1, 1}, {2, 2} }
Output: result[m][p] = { {3, 3}, {6, 6} }
Input
mat1[m][n]= { {1 2 3},{ 3 2 1},{ 1 2 3}}
mat2[p][q]= { {4 5 6},{ 6 5 4},{4 6 5}}
Output:
{28 33 29
28 31 31
28 33 29}
Multiplication of two Matrices:
The number of columns in Matrix-1 must be equal to the number of rows in Matrix-2.
The output of multiplication of Matrix-1 and Matrix-2 results with equal to the number of rows of Matrix-1 and the number of columns of Matrix-2 i.e. rslt[R1][C2]
Algorithm:
Step 1: First declare three matrices m1[3][3], m2[3][3], m3[3][3] and variables sum, i,j,k.
Step 2: Now Enter the first and second matrices elements.
Step 3: Run for loop from 0 to result. length as i:
Step 4: Nest run another for loop from 0 to result[0].length as j:
Step 5: Nest another loop from 0 to m1[0].length in k:
Step 6: Sum (m1[I][K] * m2[K][J])
Step 7: Store the sum into the resultant matrix as m3[i][j]=sum.
Step 8: End loop
Step 9: Print the resultant matrix.
C++ program to multiply two matrices:
https://www.geeksforgeeks.org/cpp-program-to-multiply-two-matrices/
Recommend
-
56
I recently read a very interesting blog post about exposing Intel SIMD intrinsics via a fork of the Scala compiler (scala-virtualized), which reports multiplicative improvements in throughput over Hot
-
50
In myprevious post, I showed how to use cdata package along with ggplot2 ‘s fa...
-
34
Table of contents Overview
-
33
Today I'd like to share an idea. It's a very simple idea. It's not fancy and it's certainly not new. In fact, I'm sure many of you have thought about it already. But if you haven't—and even if you have!—I hope you'll take...
-
12
Java Program to Perform Matrix Multiplication In the current post, I have written a java program to perform a simple matrix multiplication. For matrix multiplication the column of the first matrix should be equal to the...
-
5
How do I solve this question on multi-dimensi...
-
1
C++ Program to Generate Multiplication TableC++ Program to Generate Multiplication TableHey everyone. Welcome back to Geeks foggy. And...
-
3
Python Program to Multiply Two MatricesSkip to content Python Program to Multiply Two Matrices
-
3
Java Program to Multiply Two Matrices of any SizeSkip to content
-
1
Javascript program to generate multiplication tableSkip to content
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK