Skip to main content

Posts

Showing posts with the label Write a program to declare two 3*3 matrices

Write a program to declare two 3*3 matrices, calculate and display their sum.

 Here's a program in C++ that declares two 3x3 matrices, calculates their sum, and displays the result. #include <iostream> using namespace std; int main() {     const int ROWS = 3;     const int COLS = 3;     // Declare matrices     int matrix1[ROWS][COLS], matrix2[ROWS][COLS], sum[ROWS][COLS];     // Input elements of matrices     cout << "Enter elements of matrix1: " << endl;     for (int i = 0; i < ROWS; i++) {         for (int j = 0; j < COLS; j++) {             cin >> matrix1[i][j];         }     }     cout << "Enter elements of matrix2: " << endl;     for (int i = 0; i < ROWS; i++) {         for (int j = 0; j < COLS; j++) {             cin >> matrix2[i][j];         }     } ...