Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is C++ program of matrix .. Objectif---> you will compute each number in the output matrix with a separate thread. you will display the

This is C++ program of matrix ..

Objectif---> you will compute each number in the output matrix with a separate thread.

you will display the contents of the output matrix whenever a thread sets a value in the output matrix.

initially all the values in the output matrix will be equal to -1

rewrite the program with the thread functions and be sure that is the program is working

#include int main(void) { // Declare variables int c, d, p, q, m, n, k, tot = 0; int fst[10][10], sec[10][10], mul[10][10], transpose[10][10];

printf(" Please insert the number of rows and columns for first matrix "); scanf("%d%d", &m, &n); // Read in the elements of the first matrix printf(" Insert your matrix elements : "); for (c = 0; c < m; c++) for (d = 0; d < n; d++) scanf("%d", &fst[c][d]); // Read in the number of rows and columns for the second matrix printf(" Please insert the number of rows and columns for second matrix "); scanf(" %d %d", &p, &q); // Check if the matrices can be multiplied if (n != p) printf(" Your given matrices cannot be multiplied with each other. "); else { // Read in the elements of the second matrix printf(" Insert your elements for second matrix "); for (c = 0; c < p; c++) for (d = 0; d < q; d++) scanf("%d", &sec[c][d]); // Multiply the matrices for (c = 0; c < m; c++) { for (d = 0; d < q; d++) { for (k = 0; k < p; k++) { tot = tot + fst[c][k] * sec[k][d]; } mul[c][d] = tot; tot = 0; } } // Print the result of the matrix multiplication printf(" The result of matrix multiplication or product of the matrices is: "); for (c = 0; c < m; c++) { for (d = 0; d < q; d++) printf("%d \t", mul[c][d]); printf(" "); } // Compute the transpose of the product matrix int r = q, c = m; for (int i = 0; i < r; ++i) for (int j = 0; j < c; ++j) { transpose[j][i] = mul[i][j]; } // Print the transpose of the product matrix printf("The transpose of the product matrix is: "); for (int i = 0; i < c; ++i) { for (int j = 0; j < r; ++j) printf("%d \t", transpose[i][j]); printf(" "); } } return 0; }

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_2

Step: 3

blur-text-image_3

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

More Books

Students also viewed these Databases questions