Skip to content

MMTalal/2D-Array-Multiplication-Program

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

2D Array Multiplication Program

Description

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.

Features

  • 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.

How to Run the Program

  1. Compile the C++ code using a compiler like g++:
    g++ multiplication_array.cpp -o multiplication_array
  2. Run the compiled executable:
    ./multiplication_array
  3. 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.

Example Input & Output

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

Code Structure

  • 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.

Limitations & Possible Improvements

  • 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.

Author

Created by [Mahmoud M. Talal]

License

This project is licensed under the MIT License.

About

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.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages