Computer Networking: A Top-Down Approach (7th Edition)
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN: 9780133594140
Author: James Kurose, Keith Ross
Publisher: PEARSON
Bartleby Related Questions Icon

Related questions

Question

fill in the blanks in the code

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
expand button
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
}
expand button
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
Check Mark
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

 

Knowledge Booster
Background pattern image
Similar questions
Recommended textbooks for you
Text book image
Computer Networking: A Top-Down Approach (7th Edi...
Computer Engineering
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:PEARSON
Text book image
Computer Organization and Design MIPS Edition, Fi...
Computer Engineering
ISBN:9780124077263
Author:David A. Patterson, John L. Hennessy
Publisher:Elsevier Science
Text book image
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:9781337569330
Author:Jill West, Tamara Dean, Jean Andrews
Publisher:Cengage Learning
Text book image
Concepts of Database Management
Computer Engineering
ISBN:9781337093422
Author:Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:Cengage Learning
Text book image
Prelude to Programming
Computer Engineering
ISBN:9780133750423
Author:VENIT, Stewart
Publisher:Pearson Education
Text book image
Sc Business Data Communications and Networking, T...
Computer Engineering
ISBN:9781119368830
Author:FITZGERALD
Publisher:WILEY