Question

Write a SIMPLE C++ Program that performs the Multiplication of 2 Arrays (two dimensional arrays). Use...

Write a SIMPLE C++ Program that performs the Multiplication of 2 Arrays (two dimensional arrays). Use Comments to give a Simple description.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

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

int a[10][10],b[10][10],mul[10][10],r1,c1,r2,c2;
cout<<"\nEnter # of rows and column of first matrix(array): ";
cin>>r1>>c1;//accept #of row and col in 1st array
cout<<"\nEnter # of rows and column of second matrix(array): ";
cin>>r2>>c2; // accept row and col in 2nd matrix
if(c1!=r2)
cout<<"\nThe two arrays are not compactible for multiplication";
else
{
cout<<"\nEnter number in first array :"<<endl;
for(int i=0;i<r1;i++){
for(int j=0;j<c1;j++)
{
cout<<"\nEnter a["<<i<<"]["<<j<<"] :";
cin>>a[i][j]; // accepting 1st array from user
}
}
cout<<"\nEnter number in second array :"<<endl;
for(int i=0;i<r2;i++){
for(int j=0;j<c2;j++)
{
cout<<"\nEnter b["<<i<<"]["<<j<<"] :";
cin>>b[i][j]; // accepting second array from user
}
}
int tot=0;
for (int c = 0; c < r1; c++)
{ for (int d = 0; d < r2; d++)
{ for (int k = 0; k < c2; k++)
{ tot = tot + a[c][k] * b[k][d];// mutliplying row and column of array and adding the values
}
mul[c][d] = tot; tot = 0;
}
}

cout<<"\nThe multiplication of two array is :";
for(int i=0;i<r1;i++)
{
cout<<endl;
for(int j=0;j<c2;j++)
cout<<mul[i][j]<<" ";
}

}


}

Please upvote if you are satisfied with answer.. Also comment down if you have any doubt..

Add a comment
Know the answer?
Add Answer to:
Write a SIMPLE C++ Program that performs the Multiplication of 2 Arrays (two dimensional arrays). Use...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In C++ The Multiplication Program Step 1: Write a program that stores a multiplication table in...

    In C++ The Multiplication Program Step 1: Write a program that stores a multiplication table in a 9-by-9 two-dimensional array. Generate the multiplication table with two loops. (So you will have a nested loop that will iterate 9 times and fill the 9x9 array with the values.) Step 2: Display the table for the user to see it. a 9x9 table Step 3: Create a function that returns the product of two numbers between 1 and 9by looking up the...

  • Please use simple java code and comments no arrays Write a program that displays all the...

    Please use simple java code and comments no arrays Write a program that displays all the numbers from 100 to 1,000. ten per line, that are divisible by 5 and 6. Numbers are separated by exactly one space.

  • C++Implement only (source code) a program to determine whether two two-dimensional arrays are equivalent or not....

    C++Implement only (source code) a program to determine whether two two-dimensional arrays are equivalent or not. Two arrays are equivalent if they contain the same values in any order. The program main method defines two two-dimensional array of size 3-by-3 of type integer, and prompts the user to enter integer values to initialize the arrays. The main method calls method isEquivalent()that takes two two-dimensional arrays of integer and returns true (boolean value) if the arrays contain the same values in...

  • Java Question: Write a multithread Java program that performs matrix multiplication. In the program, you need...

    Java Question: Write a multithread Java program that performs matrix multiplication. In the program, you need to calculate each element in the result matrix in a separate thread. The code should be generic with regard to matrix size. The sizes of three matrices should be stored in variable and used. The two operand matrices and the result matrix should be printed. Thanks

  • Write a C++ function that takes a two-dimensional array and a row index. The function should...

    Write a C++ function that takes a two-dimensional array and a row index. The function should return the multiplication of all the values in the row. Write a main () program to test the function. Student Note: Please solve the question as simple as you can.

  • C++ Write a program to calculate the sum of two matrices that are stored inside two-dimensional...

    C++ Write a program to calculate the sum of two matrices that are stored inside two-dimensional arrays. Your program should include three functions: one for getting input data, one for calculating the sum of matrices, and one for printing the result. a) Function inputMatrix: This Function prompts the user to enter the data and stores data inside two-dimensional array. b) Function addMatrices: This function calculatesthe sum result of two matrices. c) Function printMatrix: This function prints the matrix to screen....

  • Given two 2-dimensional arrays, A and B, calculate the three arrays: A + B, A*B and...

    Given two 2-dimensional arrays, A and B, calculate the three arrays: A + B, A*B and A*B-1 . That is to say find the sum of the two arrays, the outer-product of the two arrays and the outer-product of A times B inverse. You can use the procedure illustrated on the web site: https://www.thecrazyprogrammer.com/2017/02/c-c-program-find-inverse-matrix.html (Links to an external site.) make the arrays 3X3, choose any values you wish make sure the determinant of B is not zero, if so change...

  • In pseudocode only Design (pseudocode) a program (name it Occurrences) to determine whether two two-dimensional arrays...

    In pseudocode only Design (pseudocode) a program (name it Occurrences) to determine whether two two-dimensional arrays are equivalent or not. Two arrays are equivalent if they contain the same values in any order. The program main method defines two two-dimensional array of size 3-by-3 of type integer, and prompts the user to enter integer values to initialize the arrays. The main method calls method isEquivalent()that takes two two-dimensional arrays of integer and returns true (boolean value) if the arrays contain...

  • write a c++ program that merges two arrays a and b. You may use the following...

    write a c++ program that merges two arrays a and b. You may use the following array contents A=5,7,8,6,3,3 and B=4,5,6,1,2,3.The merged array should exclude all repeating numbers

  • Write a C++ program that simulates a lottery game. Your program should use functions and arrays....

    Write a C++ program that simulates a lottery game. Your program should use functions and arrays. Define two global constants: - ARRAY_SIZE that stores the number of drawn numbers (for example 5) -MAX_RANGE that stores the highest value of the numbers ( for example 9 ) The program will use an array of five integers named lottery, and should generate a random number in the range of 0 through 9 for each element of the array. The user should enter...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT