
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN: 9780133594140
Author: James Kurose, Keith Ross
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
fill in the blanks in the code

Transcribed Image Text:Task 4: Multidimensional array
In this task, you will perform matrix multiplication. First, the user will input the size for each
matrix. You have to print the result of the operation if the operation is possible.
2
1 3
2.1t 1.2 t 3•3
13
4
2 1
4.1 + 2.2 † 1•3
ニ
こ| 11
2
![1
#include <stdio.h>
2
int main(){
int n, m; // size of array A. rows and columns
int n_, m_; // size of array B. rows and columns
scanf("%i %i %i %i", &n, &m, &n_, &m_);
3
5
6.
if (??){
// When can we not perform matrix multiplication?
printf("(??,??),(??,??)->(??,??), (size %i is different from %i)",??, ??);
8
10
11
12
else{
13
float A[??][??], B[??][??];
14
// Input the elements for matrix A
for (int i=0; i<??; i++){
for (int j=0; j<??; j++){
scanf("&f", &A[i] [j]);
15
16
17
18
19
}
20
}
21
// Input the elements for matrix A
for (int i=0; i<n_; i++){
for (int j=0; j<m_; j++){
scanf("&f", &B[i] [j]);
22
23
24
25
26
}
27
}
28
// Matrix multiplication
float C[??][??]; // Result of the matrix multplication
for (int i=0; i<??; i++){
for (int j=0; j<??; j++){
29
30
31
32
33
C[??][??] = 0;
34
for(int k = 0; k<??; k++){
35
[??][??] += A[??][??] * B[??] [??];
36
37
38
39
40
// Printing results
printf("\nMatrix A: \n");
for (int i=0; i<??; i++){
for (int j=0; j<??; j++){
41
42
43
44
45
printf("%.2f ", A[i][j]);
46
}
printf("\n");
}
47
48
49
printf("\n");
50
printf("\nMatrix B: \n");
for (int i=0; i<??; i++){
51
52
for (int j=0; j<??; j++){
printf("%.2f ", B[i][j]);
}
53
| 54
55
56
printf("\n");
57
}
58
printf("\n");
59
printf("\nMatrix C: \n");
for (int i=0; i<??; i++){
for (int j=0; j<??; j++){
printf("%.2f ", C[i][j]);
60
61
62
63
64
65
printf("\n");
66
}
printf("\n");
}
67
68
69
return 0;
70
}](https://content.bartleby.com/qna-images/question/b4fbdee7-4dd6-4b70-b473-f3d2f2c3fe84/a779a728-6818-4093-9af3-6013b7d3d920/j1yi41_thumbnail.png)
Transcribed Image Text:1
#include <stdio.h>
2
int main(){
int n, m; // size of array A. rows and columns
int n_, m_; // size of array B. rows and columns
scanf("%i %i %i %i", &n, &m, &n_, &m_);
3
5
6.
if (??){
// When can we not perform matrix multiplication?
printf("(??,??),(??,??)->(??,??), (size %i is different from %i)",??, ??);
8
10
11
12
else{
13
float A[??][??], B[??][??];
14
// Input the elements for matrix A
for (int i=0; i<??; i++){
for (int j=0; j<??; j++){
scanf("&f", &A[i] [j]);
15
16
17
18
19
}
20
}
21
// Input the elements for matrix A
for (int i=0; i<n_; i++){
for (int j=0; j<m_; j++){
scanf("&f", &B[i] [j]);
22
23
24
25
26
}
27
}
28
// Matrix multiplication
float C[??][??]; // Result of the matrix multplication
for (int i=0; i<??; i++){
for (int j=0; j<??; j++){
29
30
31
32
33
C[??][??] = 0;
34
for(int k = 0; k<??; k++){
35
[??][??] += A[??][??] * B[??] [??];
36
37
38
39
40
// Printing results
printf("\nMatrix A: \n");
for (int i=0; i<??; i++){
for (int j=0; j<??; j++){
41
42
43
44
45
printf("%.2f ", A[i][j]);
46
}
printf("\n");
}
47
48
49
printf("\n");
50
printf("\nMatrix B: \n");
for (int i=0; i<??; i++){
51
52
for (int j=0; j<??; j++){
printf("%.2f ", B[i][j]);
}
53
| 54
55
56
printf("\n");
57
}
58
printf("\n");
59
printf("\nMatrix C: \n");
for (int i=0; i<??; i++){
for (int j=0; j<??; j++){
printf("%.2f ", C[i][j]);
60
61
62
63
64
65
printf("\n");
66
}
printf("\n");
}
67
68
69
return 0;
70
}
Expert Solution

arrow_forward
Step 1
First some basics of matrix multiplication are if two matrices A and B of sizes a,b and x,y are to be mutiplied then bdhoul be equal to x and the mutipled matrix will be of order a*y
Going through the code I will fill the "??" blanks by writing the code below,please refer:
line 8 : if(m!=n_ && m!=0 && n!=0 && m_!=0 && n_!=0)
{
printf("(n,m),(n_,m_)->(n,m_), stmt, m,n_)
line 12 :
else {
float A[n][m],float B[n_],[m_];
line 16 ,17 for(int i=0;i<n;i++) , for(int j=0;j<m;j++)//for array A
line 23,24 for(int i=0;i<n_;i++) , for(int j=0;j<m_;j++)// for array B
Step by stepSolved in 2 steps

Knowledge Booster
Similar questions
- I need some help redoing this code, I want it to function a little differently than this. The code basically needs the following things: cannot use the power function, cannot use the sin function, must use header files (user defined functions), a loop must be used for factorial functions. Basically using these rules it should autmatically change the input of degrees to radians. The overall code should compute sin(x) using a taylor series expansion(using loops instead of using the factorial function) This is what I have, I know it works but I would like to change it.arrow_forwardC++ PLEASE MATCH OUTPUT IN PICS (Previous answers were incorrect) In this lab, you're going to be working with partially filled arrays that are parallel with each other. That means that the row index in multiple arrays identifies different pieces of data for the same person. This is a simple payroll system that just calculates gross pay given a set of employees, hours worked for the week and hourly rate. Parallel Arrays First, you have to define several arrays in your main program employee names for each employee hourly pay rate for each employee total hours worked for each employee gross pay for each employee You can use a global SIZE of 50 to initialize these arrays Second, you will need a two dimension (2-D) array to record the hours worked each day for an employee. The number of rows for the 2-D array should be the same as the arrays above since each row corresponds to an employee. The number of columns represents days of the week (7 last I looked) Functions Needed In this lab,…arrow_forwarddont use others answers will rate! Thank you! 4. Using a shift operation, write MIPS code that multiplies the number in $t0=16 by 16.arrow_forward
Recommended textbooks for you
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY

Computer Networking: A Top-Down Approach (7th Edi...
Computer Engineering
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:PEARSON

Computer Organization and Design MIPS Edition, Fi...
Computer Engineering
ISBN:9780124077263
Author:David A. Patterson, John L. Hennessy
Publisher:Elsevier Science

Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:9781337569330
Author:Jill West, Tamara Dean, Jean Andrews
Publisher:Cengage Learning

Concepts of Database Management
Computer Engineering
ISBN:9781337093422
Author:Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:Cengage Learning

Prelude to Programming
Computer Engineering
ISBN:9780133750423
Author:VENIT, Stewart
Publisher:Pearson Education

Sc Business Data Communications and Networking, T...
Computer Engineering
ISBN:9781119368830
Author:FITZGERALD
Publisher:WILEY