Question

In: Computer Science

The third worksheet ("Ex. 3") contains 2 4x4 matrices, plus space for a third. Write a...

The third worksheet ("Ex. 3") contains 2 4x4 matrices, plus space for a third. Write a program that will read the first 2 matrices into array "B" and "C" . Create a 3rd array, "A" that is the result of matrix B + matrix C (i.e |A| = |B| + |C|). Output that array in the indicated cells (upper left = cell K1) To do this, use the rule for array addition for each matrix element: aij = bij + cij where i and j indicate the location (row, column) of the matrix element. NOTE: You must use arrays to get credit for this exercise. Keep close track of which loop is representing which index.

74 21 95 8 16 30 40 5
52 79 41 23 + 33 8 32 5 =
3 91 33 37 24 4 4 12
93 68 40 74 24 27 24 15

Solutions

Expert Solution

The program is basically keeping a track of addition of each element corresponding to the same indexes i,j and storing them in a third array of same size.

so, let us first understand the concept of array addition

Our program will basically add all the elements corresponding to i=1 i.e j=1,2,3,4 i.e 4 iterations. After the completion of i=1, it will move on to 2,3,4 respectively and add its iterations as well

As the language is not specified, for the comfort of students, I will be using basic C code.

*******************************************************************************************************************

#include <stdio.h>

#include <stdlib.h>

int main()

{

int i,j,k,s=0;

int a[4][4], b[4][4], c[4][4]; //declaring the three 4*4 arrays

//getting the input for array b

for(i=0;i<4;i++)

{for(j=0;j<4;j++)

{

scanf("%d",&b[i][j]);

}

}

//getting the input for array c

for(i=0;i<4;i++)

{for(j=0;j<4;j++)

{

scanf("%d",&c[i][j]);

}

}

//adding the corresponding elements of b and c and storing it in a

for(i=0;i<4;i++)

{for(j=0;j<4;j++)

{

a[i][j]=b[i][j]+c[i][j];

}

}

}

**************************************************************************************************************

An array always store values from 0,0 index, so our code will work upon 0,1,2,3 and its corresponding 4 iterations.

Now let us look for loop iterations.

loop 1 i=0:

i=0,j=0: 74+16

i=0,j=1: 21+30

i=0,j=2: 95+40

i=0,j=3: 8+5

loop 2 i=1:

i=1,j=0: 52+33

i=1,j=1: 79+8

i=1,j=2: 41+32

i=1,j=3: 23+5

loop 3 i=2:

i=2,j=0: 3+24

i=2,j=1:91+4

i=2,j=2:33+4

i=2,j=3:97+12

loop 4 i=3:

i=3,j=0: 93+24

i=3,j=1: 68+27

i=3,j=2: 40+24

i=3,j=3: 74+15

Therefore the final array A becomes

90 51 135 31
85 87 73 28
27 95 37 109
117 95 64 89

Related Solutions

In VBA, write a code that does as follows: The first worksheet ("Ex. 1") has a...
In VBA, write a code that does as follows: The first worksheet ("Ex. 1") has a list of 50 numbers. Write a program that will read them into an array, then will calculate and output the following: - How many of the numbers are even (output in E2) - How many of the numbers are greater than 300 (output in E3) - The average of the numbers (output in E4) - In column B, output next to each number, the...
Let V be the vector space of 2 × 2 real matrices and let P2 be...
Let V be the vector space of 2 × 2 real matrices and let P2 be the vector space of polynomials of degree less than or equal to 2. Write down a linear transformation T : V ? P2 with rank 2. You do not need to prove that the function you write down is a linear transformation, but you may want to check this yourself. You do, however, need to prove that your transformation has rank 2.
The data worksheet entitled "FUELCON4" contains the following variables for all 50 states plus the District...
The data worksheet entitled "FUELCON4" contains the following variables for all 50 states plus the District of Columbia. FUELCON (y): Per capita fuel consumption in gallons DRIVERS (x1): The ratio of licensed drivers to private and commercial motor vehicles registered HWYMILES (x2):   The number of miles of federally funded highways GASTAX (x3) : The tax per gallon of gasoline in cents INCOME (x4): The average household income in dollars Run the regression analysis with FUELCON as the dependent variable and...
Let V = R^2×2 be the vector space of 2-by-2 matrices with real entries over the...
Let V = R^2×2 be the vector space of 2-by-2 matrices with real entries over the scalar field R. We can define a function L on V by L : V is sent to V L = A maps to A^T , so that L is the “transpose operator.” The inner product of two matrices B in R^n×n and C in R^n×n is usually defined to be <B,C> := trace (BC^T) , and we will use this as our inner...
Derive the Dirac gamma matrices for 2-space dimensions and 1-time dimension.
Derive the Dirac gamma matrices for 2-space dimensions and 1-time dimension.
Find the dimensions of the following linear spaces. (a) The space of all 3×4 matrices (b)...
Find the dimensions of the following linear spaces. (a) The space of all 3×4 matrices (b) The space of all upper triangular 5×5 matrices (c) The space of all diagonal 6×6 matrices
Use synthetic division to divide (-3x3-4x4− 20 − 2?) ÷ (? + 2). Write your answer...
Use synthetic division to divide (-3x3-4x4− 20 − 2?) ÷ (? + 2). Write your answer in the form ???????? ÷ ??????? = ???????? + remainder/divisor
Question 1 A worksheet is composed of multiple workbooks. True False Question 2 A1 contains 3...
Question 1 A worksheet is composed of multiple workbooks. True False Question 2 A1 contains 3 and A2 contains 4. Cell B2 contains = $A$1 ^ $A$1. What value will cell C2 display if you copy the formula from cell B2 to cell C2? 0 27 12 16 Question 3 Which of the following cannot be a cell reference? cell1 B3 $C5 $F$3 none of the above is correct Question 4 What are the 3 most common types of data...
Nike Inc. - Write a 500-750-word analysis of the significance of Space, Grand, and QSP Matrices...
Nike Inc. - Write a 500-750-word analysis of the significance of Space, Grand, and QSP Matrices regarding their relevance for strategic planning. Describe the key information for each and how information from each will influence recommendations for strategy selection, planning, and implementation. Without prematurely determining and formalizing strategic goals and objectives, begin thinking about possible strategies to capitalize and add value to the organization based on the analysis of this information. Be sure to cite three to five relevant and...
Complete the worksheet according to the following guidelines: In the space provided, write each term’s definition...
Complete the worksheet according to the following guidelines: In the space provided, write each term’s definition as used in ecology. You must define the term in your own words; do not simply copy the definition from a textbook. Provide APA-formatted citations for all paraphrased responses inserted into this worksheet. Every cited work must also have a corresponding reference entry on the References page at the end of this worksheet. In the space provided after each term’s definition, provide an explanation...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT