0% found this document useful (0 votes)
18 views3 pages

C++ QUIZ 7

The document contains C++ code to perform addition and multiplication of two 3x3 matrices. It first prompts the user to input values for the two matrices. It then displays the matrices and calculates and displays the sum and product matrices by iterating through the rows and columns and performing the respective operations at each element. The code uses nested for loops to iterate through the 2D arrays that represent the matrices to read in values, display contents, and perform the calculations.

Uploaded by

Rockstar Thutha
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
0% found this document useful (0 votes)
18 views3 pages

C++ QUIZ 7

The document contains C++ code to perform addition and multiplication of two 3x3 matrices. It first prompts the user to input values for the two matrices. It then displays the matrices and calculates and displays the sum and product matrices by iterating through the rows and columns and performing the respective operations at each element. The code uses nested for loops to iterate through the 2D arrays that represent the matrices to read in values, display contents, and perform the calculations.

Uploaded by

Rockstar Thutha
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/ 3

Abdullah Khan Raja

BCS231095
Quiz no 07

Task 1
#include <iostream>
using namespace std;
int main()

{
int matrix1[3][3];

int matrix2[3][3];
int sumMatrix[3][3];
int productMatrix[3][3];

cout << "ENTER VALUES for 1st MATRIX " <<endl;


for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 3; ++j) {
cout << "Enter value for ROW "<< i <<"AND COLUMN " <<j << " : " ;
cin >> matrix1[i][j];
}
}

cout << "ENTER VALUES FOR 2nd MATRIX: " <<endl;


for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 3; ++j) {
cout << "Enter value for ROW " << i << "AND COLUMN " << j << " :
";
cin >> matrix2[i][j];
}
}

cout << "VALUES OF BOTH MATRIX: " <<endl;


cout << "Matrix 1:" <<endl;
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 3; ++j) {
cout << matrix1[i][j] << " ";
}
cout <<endl;
}
cout <<endl;

cout << "Matrix 2:" << endl;


for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 3; ++j) {
std::cout << matrix2[i][j] << " ";
}
cout << endl;
}
cout << endl;

cout << "RESULT OF ADDED MATRIX: " << endl;


for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 3; ++j) {
sumMatrix[i][j] = matrix1[i][j] + matrix2[i][j];
cout << sumMatrix[i][j] << " ";
}
cout << endl;
}
cout << endl;

cout << "RESULT OF MULTIPLIED MATRIX: " <<endl;


for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 3; ++j) {
productMatrix[i][j] = 0;
for (int k = 0; k < 3; ++k) {
productMatrix[i][j] += matrix1[i][k] * matrix2[k][j];
}
cout << productMatrix[i][j] << " ";
}
cout <<endl;
}

return 0;
}
OUTPUT:

You might also like