"3x3 matrix multiplication in c++" Code Answer's
You're definitely familiar with the best coding language C++ that developers use to develop their projects and they get all their queries like "3x3 matrix multiplication in c++" answered properly. Developers are finding an appropriate answer about 3x3 matrix multiplication in c++ related to the C++ coding language. By visiting this online portal developers get answers concerning C++ codes question like 3x3 matrix multiplication in c++. Enter your desired code related query in the search bar and get every piece of information about C++ code related question on 3x3 matrix multiplication in c++.
matrix multipliction in c++
#include <iostream>
using namespace std;
int main()
{
int a[10][10], b[10][10], mult[10][10], r1, c1, r2, c2, i, j, k;
cout << "Enter rows and columns for first matrix: ";
cin >> r1 >> c1;
cout << "Enter rows and columns for second matrix: ";
cin >> r2 >> c2;
// If column of first matrix in not equal to row of second matrix,
// ask the user to enter the size of matrix again.
while (c1!=r2)
{
cout << "Error! column of first matrix not equal to row of second.";
cout << "Enter rows and columns for first matrix: ";
cin >> r1 >> c1;
cout << "Enter rows and columns for second matrix: ";
cin >> r2 >> c2;
}
// Storing elements of first matrix.
cout << endl << "Enter elements of matrix 1:" << endl;
for(i = 0; i < r1; ++i)
for(j = 0; j < c1; ++j)
{
cout << "Enter element a" << i + 1 << j + 1 << " : ";
cin >> a[i][j];
}
// Storing elements of second matrix.
cout << endl << "Enter elements of matrix 2:" << endl;
for(i = 0; i < r2; ++i)
for(j = 0; j < c2; ++j)
{
cout << "Enter element b" << i + 1 << j + 1 << " : ";
cin >> b[i][j];
}
// Initializing elements of matrix mult to 0.
for(i = 0; i < r1; ++i)
for(j = 0; j < c2; ++j)
{
mult[i][j]=0;
}
// Multiplying matrix a and b and storing in array mult.
for(i = 0; i < r1; ++i)
for(j = 0; j < c2; ++j)
for(k = 0; k < c1; ++k)
{
mult[i][j] += a[i][k] * b[k][j];
}
// Displaying the multiplication of two matrix.
cout << endl << "Output Matrix: " << endl;
for(i = 0; i < r1; ++i)
for(j = 0; j < c2; ++j)
{
cout << " " << mult[i][j];
if(j == c2-1)
cout << endl;
}
return 0;
}
Source: www.programiz.com
All those coders who are working on the C++ based application and are stuck on 3x3 matrix multiplication in c++ can get a collection of related answers to their query. Programmers need to enter their query on 3x3 matrix multiplication in c++ related to C++ code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about 3x3 matrix multiplication in c++ for the programmers working on C++ code while coding their module. Coders are also allowed to rectify already present answers of 3x3 matrix multiplication in c++ while working on the C++ language code. Developers can add up suggestions if they deem fit any other answer relating to "3x3 matrix multiplication in c++". Visit this developer's friendly online web community, CodeProZone, and get your queries like 3x3 matrix multiplication in c++ resolved professionally and stay updated to the latest C++ updates.