Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program which multiplies two matrices. The matrices may be any size, contain integers, and will come as input from the user. Each matrix

Write a program which multiplies two matrices. The matrices may be any size, contain integers, and will come as input from the user. Each matrix will be input with the columns separated by spaces and the rows each on a new line. The end of each matrix will be specified by an empty line with no integers. Your program should print the resulting matrix with each column separated by a space, and each row on a new line.

Remember that the matrix product is defined as:

(AB)ij = sum of (Aik * Bkj) for k = 1 to m (where m is the number of columns in A)

Your program should output an error if the dimensions of the input matrices are incompatible (the number of columns in the first is not equal to the number of rows in the second).

Each input matrix should be stored in a multidimensional integer array. You may also want to use a multidimensional array to store the result matrix. All three matrices have sizes less or equal 10 by 10.

The program should print a string of text to the terminal before getting input from the user. A session should look like one of the following examples (including whitespace and formatting), with a possibly matrix in the output:

Enter first matrix: 1 2 3 4 5 6 Enter second matrix: 7 8 9 0 1 2 The product is: 28 14 79 44 
Enter first matrix: 1 2 3 Enter second matrix: 4 5 6 The two matrices have incompatible dimensions. 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

C++ Database Development

Authors: Al Stevens

1st Edition

1558283579, 978-1558283572

More Books

Students also viewed these Databases questions

Question

Explain the function and purpose of the Job Level Table.

Answered: 1 week ago