This C++ program allows the user to input a 2D array (matrix) and calculates the multiplication of all its elements. The program first asks the user for the number of rows and columns, then prompts them to enter the values for each element in the matrix. Finally, it computes and displays the product of all elements in the matrix using function.
- Accepts user input for the dimensions of the matrix (rows and columns).
- Accepts user input for the matrix elements.
- Computes the multiplication of all elements in the matrix.
- Displays the result to the user.
- Compile the C++ code using a compiler like g++:
g++ multiplication_array.cpp -o multiplication_array
- Run the compiled executable:
./multiplication_array
- Follow the on-screen instructions:
- Enter the number of rows and columns.
- Enter values for each element in the matrix.
- View the multiplication result of all elements.
Input:
How many rows do you want for the 2D array:
2
How many columns do you want for the 2D array:
3
You will now input the values for your elements.
Input your value in row No. 1 and column No. 1 please:
2
Input your value in row No. 1 and column No. 2 please:
3
Input your value in row No. 1 and column No. 3 please:
4
Input your value in row No. 2 and column No. 1 please:
5
Input your value in row No. 2 and column No. 2 please:
6
Input your value in row No. 2 and column No. 3 please:
7
Output:
The multiplication of your 2D array elements is 5040
multiplication_Array(int arr[100][100], int row, int col):- Loops through the matrix and calculates the product of all elements.
- Prints the final multiplication result.
main():- Handles user input for the matrix dimensions and values.
- Calls
multiplication_Array()to compute and display the result.
- Fixed array size (100x100): The program currently uses a fixed-size array. Using dynamic memory allocation would improve flexibility.
- Integer overflow risk: If the product is too large, it may exceed the integer limit. Using long long int or floating-point numbers could prevent overflow.
Created by [Mahmoud M. Talal]
This project is licensed under the MIT License.