Question

Develope a CPP program that multiplies two square matrixes. Your program will follow the steps below. 1. Print a statement welcoming the user to the program. 2. Ask the user the size of the matrix. (You only need one number since it will be square.) 3. Ask the user for the values of the first matrix. 4. Aks the user for the values of the second matrix 5. Display the result of multiplying the two matrixes.

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

#include <iostream>

using namespace std;

int main() {

int n;

cout << "Welcome to Matrix Multiply\n";

cout << "Enter size of Matrix:\n";

cin >> n;

int A[n][n], B[n][n], C[n][n];

for(int i=0; i<n; i++) // taking user input of matrix A

for(int j=0; j<n; j++)

{

cout << "Enter Value for Position A[" << i <<"][" << j <<"]" << endl;

cin >> A[i][j];

}

for(int i=0; i<n; i++) // taking user input of matrix B

for(int j=0; j<n; j++)

{

cout << "Enter Value for Position B[" << i <<"][" << j <<"]" << endl;

cin >> B[i][j];

}

for (int m = 0; m < n; m++) // calculating the product of A and B

for (int n1 = 0; n1 < n; n1++)

{

C[m][n1] = 0;

for (int o = 0; o < n; o++)

{

C[m][n1] += A[m][o] * B[o][n1];

}

}

for(int i=0; i<n; i++) // printing output matrix C

for(int j=0; j<n; j++)

cout << "C[" << i <<"][" << j <<"]=" << C[i][j] << endl;

}

/*SAMPLE OUTPUT

Welcome to Matrix Multiply

Enter size of Matrix:

2

Enter Value for Position A[0][0]

1

Enter Value for Position A[0][1]

2

Enter Value for Position A[1][0]

3

Enter Value for Position A[1][1]

4

Enter Value for Position B[0][0]

5

Enter Value for Position B[0][1]

6

Enter Value for Position B[1][0]

7

Enter Value for Position B[1][1]

8

C[0][0]=19

C[0][1]=22

C[1][0]=43

C[1][1]=50

*/

// Hit the thumbs up if you are satisfied with the answer. Happy Learning!

Add a comment
Know the answer?
Add Answer to:
Develope a CPP program that multiplies two square matrixes. Your program will follow the steps below....
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
  • For the program described below, document your code well. Use descriptive identifier names. Use s...

    For the program described below, document your code well. Use descriptive identifier names. Use spaces and indentation to improve readability. Include a beginning comment block as well as explanatory comments throughout. In the beginning comment block, add your name, program name, date written, program description. The description briefly describes what the program does. Include a comment at the beginning of each method to describe what the method does. Write a program to perform operations on square matrices (i.e. equal number...

  • For the program described below, document your code well. Use descriptive identifier names. Use spaces and...

    For the program described below, document your code well. Use descriptive identifier names. Use spaces and indentation to improve readability. Include a beginning comment block as well as explanatory comments throughout. In the beginning comment block, add your name, program name, date written, program description. The description briefly describes what the program does. Include a comment at the beginning of each method to describe what the method does. Write a program to perform operations on square matrices (i.e. equal number...

  • Assignment Input from the user 9, 64-bit, floating-point values as a 3x3, row-major, multi-dimensional array. This...

    Assignment Input from the user 9, 64-bit, floating-point values as a 3x3, row-major, multi-dimensional array. This will be the 3x3 matrix. Then, input 3, 64-bit, floating-point values. This will be a single-dimensional array and is the vector. Your program will simply ask the user to enter matrix values. Remember, there are 9 of these, but they need to be stored into a 3x3 multi-dimensional array (row-major). Then, your program will ask for the vector values, which will be stored into...

  • Write a program called problem4.cpp to implement an automatic teller machine (ATM) following the BankAccount class...

    Write a program called problem4.cpp to implement an automatic teller machine (ATM) following the BankAccount class the we implemented in class. Your main program should initialize a list of accounts with the following values and store them in an array Account 101 → balance = 100, interest = 10% Account 201 → balance = 50, interest = 20% Account 108 → balance = 200, interest = 11% Account 302 → balance = 10, interest = 5% Account 204 → balance...

  • You must write a C program that prompts the user for two numbers (no command line...

    You must write a C program that prompts the user for two numbers (no command line input) and multiplies them together using “a la russe” multiplication. The program must display your banner logo as part of a prompt to the user. The valid range of values is 0 to 6000. You may assume that the user will always enter numerical decimal format values. Your program should check this numerical range (including checking for negative numbers) and reprompt the user for...

  • I am having trouble figuring out why my program will not make any columns, just rows....

    I am having trouble figuring out why my program will not make any columns, just rows. I need to display a square. The instructions are provided below. (This for my C++ class) Write a program that displays a square. Ask the user for the square’s size. Only accept positive integer numbers (meaning choose a data type that holds positive integer values). The size the user gives you will determine the length and width of the square. The program should then...

  • Write a C program (not C++) that calls a function to multiply a matrix (two dimensional...

    Write a C program (not C++) that calls a function to multiply a matrix (two dimensional array). The main program should ask the user to enter an integer that will be used as the matrix “adder” and then call the function. The function should perform a matrix increment (every element of the array is incremented by the same value) and assign the result to another array. The function should be flexible enough to work with any array size and “adder”,...

  • code in C++ Create a program that uses the pass by reference operator instead of the...

    code in C++ Create a program that uses the pass by reference operator instead of the return command. Your main program will need to: create empty variables call void function 1 with no input to display your name to the screen call function 2 to collect the square feet that a gallon of paint covers from user call function 2 to collect the square feet of wall that needs to be painted call function 3 to calculate the number of...

  • Language is C++ Basic principles and theory of structured programming in C++ by implementing the class:...

    Language is C++ Basic principles and theory of structured programming in C++ by implementing the class: Matrix Use these principles and theory to help build and manipulate instances of the class (objects), call member functions Matrix class implementation from the main function file and, in addition, the Matrix class must have its interface(Matrix.h) in a separate file from its implementation (Matrix.cpp). The code in the following files: matrix.h matrix.cpp matrixDriver.h Please use these file names exactly. Summary Create three files...

  • 1. (30 Points) Write a MATLAB program that displays "The multiplication of 10 multiplied by integers...

    1. (30 Points) Write a MATLAB program that displays "The multiplication of 10 multiplied by integers of 1 through 15. Display your result back to the user with 2 decimal places (yes, 2 decimal places). You must implement your code using a for loop. The result should have the following format: The multiplication of 10*1 =10.00 The multiplication of 10*2 =20.00 The multiplication of 10'3=30.00 The multiplication of 10*15=150.00 2. (35 Points) Write MATLAB code to prompt a user for...

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
ADVERTISEMENT