Computer Systems: A Programmer's Perspective (3rd Edition)
3rd Edition
ISBN: 9780134092669
Author: Bryant, Randal E. Bryant, David R. O'Hallaron, David R., Randal E.; O'Hallaron, Bryant/O'hallaron
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 6, Problem 6.45HW
Program Plan Intro
Given Information:
The given code is:
//method to transpose matrix
void transpose(int *dst, int *src, int dim)
{
//variable declaration
int i,j;
//traverse through matrix
for(i=0;i<dim;i++)
for(j=0;j<dim;j++)
//transpose
dst[j*dim+i]=src[i*dim+j];
}
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Write a C function, void sum_rows( int a*,int sum*,int n) to compute the sum of row elements in a nxn matrix and store the result in vector sum[].
Can this function be optimized by the compiler? If No, why?
Rewrite the function to remove the optimization blocker.
Write a code in "C++"that can swap all the values of its first row with its last row in a [n×m] matrix After swapping, add all the values of the last column.(using C++ only)
Write a C++ program that fills a 5 x 5 matrix of integers. The matrix must be a static matrix; its size must be fixed at compile-time. Display the contents of the matrix. Query the user for an integer. Pass the matrix and the integer to a bool function that searches for the first occurrence, and only the first occurrence, of the integer in thematrix. If the integer is found, the function returns true (and passes back the row and column coordinates of the first occurrence of the integer); if not, the function returns false. Main then displays whether the integer was found in the matrix and if so, the coordinates of the first occurrence. The use of a break to exit a loop or a function should be avoided.
My code does not find the location of the first occurrence and does not use a bool function. Can you please help me to find the error.
This is my code:
#include <iostream>
#include <random>
using namespace std;
int main()
{
int guess, array[5][5];
bool found = false;
for(int…
Chapter 6 Solutions
Computer Systems: A Programmer's Perspective (3rd Edition)
Ch. 6.1 - Prob. 6.1PPCh. 6.1 - Prob. 6.2PPCh. 6.1 - Prob. 6.3PPCh. 6.1 - Prob. 6.4PPCh. 6.1 - Prob. 6.5PPCh. 6.1 - Prob. 6.6PPCh. 6.2 - Prob. 6.7PPCh. 6.2 - Prob. 6.8PPCh. 6.4 - Prob. 6.9PPCh. 6.4 - Prob. 6.10PP
Ch. 6.4 - Prob. 6.11PPCh. 6.4 - Prob. 6.12PPCh. 6.4 - Prob. 6.13PPCh. 6.4 - Prob. 6.14PPCh. 6.4 - Prob. 6.15PPCh. 6.4 - Prob. 6.16PPCh. 6.5 - Prob. 6.17PPCh. 6.5 - Prob. 6.18PPCh. 6.5 - Prob. 6.19PPCh. 6.5 - Prob. 6.20PPCh. 6.6 - Prob. 6.21PPCh. 6 - Prob. 6.22HWCh. 6 - Prob. 6.23HWCh. 6 - Suppose that a 2 MB file consisting of 512-byte...Ch. 6 - The following table gives the parameters for a...Ch. 6 - The following table gives the parameters for a...Ch. 6 - Prob. 6.27HWCh. 6 - This problem concerns the cache in Practice...Ch. 6 - Suppose we have a system with the following...Ch. 6 - Suppose we have a system with following...Ch. 6 - Suppose that a program using the cache in Problem...Ch. 6 - Repeat Problem 6.31 for memory address0x16E8 A....Ch. 6 - Prob. 6.33HWCh. 6 - Prob. 6.34HWCh. 6 - Prob. 6.35HWCh. 6 - Prob. 6.36HWCh. 6 - Prob. 6.37HWCh. 6 - Prob. 6.38HWCh. 6 - Prob. 6.39HWCh. 6 - Given the assumptions in Problem 6.38, determine...Ch. 6 - You are writing a new 3D game that you hope will...Ch. 6 - Prob. 6.42HWCh. 6 - Prob. 6.43HWCh. 6 - Prob. 6.45HWCh. 6 - Prob. 6.46HW
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- Write a C++ program that fills a 5 x 5 matrix of integers. The matrix must be a static matrix; its size must be fixed at compile-time. Display the contents of the matrix. Query the user for an integer. Pass the matrix and the integer to a bool function that searches for the first occurrence, and only the first occurrence, of the integer in thematrix. If the integer is found, the function returns true (and passes back the row and column coordinates of the first occurrence of the integer); if not, the function returns false.arrow_forwardFor the following C++ code find and write the recurrence relation. You need to model the runtime of function "Func" in terms of n. (only the recurrence relation in terms of n, No output of the code or final runtime analysis is required) s= array L[] start index e= array L[] end index void Func(int L[], int s, int e) { if (s < e) { i=s-1; for (int j = s; j <= e - 1; j++) { if (A[j] <= x) { i++; swap (&L[i], &L[j]); } } swap (&L[i + 1], &L[e]); int k = i+1; Func(L, s, k - 1); Func(L, k + 1, e); } } Please explain how you get the relation Thank you!arrow_forwardWrite a function that takes a matrix of order 3 and prints the transpose of it. The transpose should be stored in a different matrix.Test the function in main().For example:Matrix =1 2 34 5 67 8 9Transpose =1 4 72 5 83 6 9 write code for it in c++arrow_forward
- Write a code in "C"that can swap all the values of its first row with its last row in a [n×m] matrix After swapping, add all the values of the last column.arrow_forwardAn MxN matrix can be represented by a 1-D array of size M*N as follows: The elements at index 0 to N-1 corerspond to the first row of the matrix The elements at index N to 2*N-1 corerspond to the second row of the matrix so on The elements at index (M-1)*N to M*N corerspond to the last row of the matrix Problem Write a function to find the transpose of a matrix. Save the resultant matrix in the 1-D array that is passed as argument to the function. If the function succeeds return 1 otherwise return -1. int MatrixTranspose(int matrix1[], int r1, int c1, int resultant[], int &r2, int &c2) { } int main(int argc, char *argv[]) { return 0; } THIS IN C++.arrow_forwardWhen dealing with large dense symmetric matrix it is recommended that to either store upper right or lower left entries only to avoid redundancy and thereby saving a lot of space (particularly when the matrix elements are of double type or any other user-defined datatype). Let us assume that we have decided to store only the upper right entries of a matrix inside a 1D array in the row-major arrangement. 1. Design an algorithm for accepting a symmetric matrix from the user and printing the same matrix. 2. Design an algorithm for multiplying a given symmetric matrix stored in a 1D array with a compatible vector.arrow_forward
- in c++ please Write a function called Replace All that cerpts two parameters a matrix of 100 elements of type inter and an interval y. The function must - Replace every positive matrix element by the values +5and Replace every negative matrix element by the value - 5 and - Replace every mero try the value y.arrow_forwardGiven a matrix of m x n elements (m rows, n columns),return all elements of the matrix in spiral order.For example,Given the following matrix:[ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ]]You should return [1,2,3,6,9,8,7,4,5].""" def spiral_traversal(matrix): res = [] if len(matrix) == 0: return res row_begin = 0 row_end = len(matrix) - 1 col_begin = 0 col_end = len(matrix[0]) - 1 while row_begin <= row_end and col_begin <= col_end: for i in range(col_begin, col_end+1): res.append(matrix[row_begin][i]) row_begin += 1 for i in range(row_begin, row_end+1): res.append(matrix[i][col_end]) col_end -= 1 if row_begin <= row_end: for i in range(col_end, col_begin-1, -1): res.append(matrix[row_end][i]) row_end -= 1 if col_begin <= col_end: for i in range(row_end, row_begin-1, -1): res.append(matrix[i][col_begin]) col_begin += 1arrow_forwardImplement a range function for a dynamic array which returns a new dynamic array that is a subset of the original. input parameters: array - (the array and any related parameters) start - index of the first elementend - index of the last elementInterval - An integer number specifying the incrementation of index This function returns a new dynamic array containing the elements from the start thru the end indices of the original array.All array indexing must be done using pointer arithmetic. For example, given the array: 49 96 99 47 76 29 22 16 30 22 If the start and end positions were 5 and 9 with step 2, return a new dynamic array: 29 16 22 Please use following main to test your function. int main(){int *p = new int[10]{49,96,99,47,76,29,22,16,30,22}; int *q = range(p,10,5,9,2);for(int i=0;i<3;i++) cout<<q[i]<<" "; // print 29 16 22 cout<<endl;delete [] q;q = range(p,10,1,8,3); for(int i=0;i<3;i++)cout<<q[i]<<" "; // print 96 76 16 cout<<endl;…arrow_forward
- In line no. 4, we want "count" to be assigned a row vector with two zeros as its elements. What should be the value of "b" to do that?arrow_forwardMatrix multiplication plays an important role in a number of applications. Two matrices can only be multiplied if the number of columns of the fi rst matrix is equal to the number of rows in the second.Let’s assume we have an m × n matrix A and we want to multiply it by an n × p matrix B. We can express their product as an m × p matrix denoted by AB (or A ⋅ B). If we assign C = AB, and ci,j denotes the entry in C at position (i, j), then for each element i and j with 1 ≤ i ≤ m and 1 ≤ j ≤ p. Now we want to see if we can parallelize the computation of C. Assume that matrices are laid out in memory sequentially as follows: a1,1, a2,1, a3,1, a4,1, ..., etc.Assume that we are going to compute C on both a single core shared memory machine and a 4-core shared-memory machine. Compute the speedup we would expect to obtain on the 4-core machine, ignoring any memory issues.Repeat above Exercise, assuming that updates to C incur a cache miss due to false sharing when consecutive elements are in a…arrow_forwardIn line no. 4, we want "count" to be assigned a row vector with two zeros as its elements. What should be the value of "a" to do that? *arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education