Programming in C
4th Edition
ISBN: 9780321776419
Author: Stephen G. Kochan
Publisher: Addison-Wesley
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 7, Problem 12E
A matrix M with i rows, j columns can be transposed into a matrix N having j rows and i columns by simply setting the value of Na,b equal to the value of Mb,a for all relevant values of a and b.
- a. Write a function t that takes as an argument a 4 × 5 matrix and a 5 × 4 matrix. Have the function transpose the 4 × 5 matrix and store the results in the 5 × 4 matrix. Also write a m routine to test the function.
- b. Using variable-length arrays, rewrite the t function developed in exercise 12a to take the number of rows and columns as arguments, and to transpose the matrix of the specified dimensions.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Write an interactive modular program that uses a user-
defined function to accept a M x N matrix. Then write a
function to compute column averages and row averages,
and print the entire matrix with averages shown in the
respective rows and columns.
C++
Given an integer matrix of size M × N. Find the number of the first of its columns containing an equal number of positive and negative elements (zero elements of the matrix must be ignored).
If there are no such columns, then print 0. Write a function to solve this problem.
void max_each_column(int a[20][20], int n, int m)
3 3
1 2 -3
4 0 3
7 -8 0
Output:
1
Consider an input string TAM of letters ‘A’, ‘M’, and ‘T’. This string, which is given by the user, ends with ‘#’. It should be stored in a table (or array), called TAMUK. The number of each of these letters is unknown. We have a function, called SWAP(TAM,i,j), which places the ith letter in the jth entry of string TAM and the jth letter in the ith entry of TAM. Note that SWAP(TAM,i,j) is defined for all integers i and j between 0 and length(TAM)–1, where length(TAM) is the number of letters of TAM. 1. Using our algorithmic language, write an algorithm, called Sort_TAM, which sorts the letters in the array TAMUK in a way that all T’s appear first, followed by all A’s, and followed by all M’s. The algorithm Sort_TAM should have one parameter: The array TAMUK. Also, your solution is correct only if the following four constraints are satisfied: - Constraint 1: Each letter (‘A’, ‘M’, or ‘T’) is evaluated only once. - Constraint 2: The function SWAP(TAM,i,j) is used only when it is…
Chapter 7 Solutions
Programming in C
Ch. 7 - Type in and run the 17 programs presented in this...Ch. 7 - Prob. 2ECh. 7 - Modify Program 7.8 so that the value of e is...Ch. 7 - Modify Program 7.8 so that the value of g is...Ch. 7 - Prob. 6ECh. 7 - Write a function that raises an integer to a...Ch. 7 - Prob. 8ECh. 7 - The least common multiple (1cm) of two positive...Ch. 7 - Prob. 10ECh. 7 - Write a function called a that takes two...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
The following hands-on exercises develop additional techniques for manipulating and
accessing controls placed o...
Introduction To Programming Using Visual Basic (11th Edition)
A (n) _______operator determines if a specific relationship exists between two values.
Starting Out With Visual Basic (7th Edition)
Compare the method headers of getPrice and printTicket in Code 2.1. Apart from their names, what is the main di...
Objects First with Java: A Practical Introduction Using BlueJ (6th Edition)
Suppose that a 2 MB file consisting of 512-byte logical blocks is stored on a disk drive with the following cha...
Computer Systems: A Programmer's Perspective (3rd Edition)
3.12 (Date Create a class called Date that includes three pieces Of information as data
members—a month (type ...
C++ How to Program (10th Edition)
Suppose the Vole communicates with a printer using the technique of memory-mapped I/O. Suppose also that addres...
Computer Science: An Overview (13th Edition) (What's New in Computer Science)
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
- consider an input string TAM of letters ‘A’, ‘M’, and ‘T’. This string, which is given by the user, ends with ‘#’. It should be stored in a table (or array), called TAMUK. The number of each of these letters is unknown. We have a function, called SWAP(TAM,i,j), which places the ith letter in the jth entry of string TAM and the jth letter in the ith entry of TAM. Note that SWAP(TAM,i,j) is defined for all integers i and j between 0 and length(TAM)–1, where length(TAM) is the number of letters of TAM. 1. Using our algorithmic language, write an algorithm, called Sort_TAM, which sorts the letters in the array TAMUK in a way that all T’s appear first, followed by all A’s, and followed by all M’s. The algorithm Sort_TAM should have one parameter: The array TAMUK. Also, your solution is correct only if the following four constraints are satisfied: - Constraint 1: Each letter (‘A’, ‘M’, or ‘T’) is evaluated only once. - Constraint 2: The function SWAP(TAM,i,j) is used only when it is…arrow_forwardconsider an input string TAM of letters ‘A’, ‘M’, and ‘T’. This string, which is given by the user, ends with ‘#’. It should be stored in a table (or array), called TAMUK. The number of each of these letters is unknown. We have a function, called SWAP(TAM,i,j), which places the ith letter in the jth entry of string TAM and the jth letter in the ith entry of TAM. Note that SWAP(TAM,i,j) is defined for all integers i and j between 0 and length(TAM)–1, where length(TAM) is the number of letters of TAM. 1. Using our algorithmic language, write an algorithm, called Sort_TAM, which sorts the letters in the array TAMUK in a way that all T’s appear first, followed by all A’s, and followed by all M’s. The algorithm Sort_TAM should have one parameter: The array TAMUK. Also, your solution is correct only if the following four constraints are satisfied: - Constraint 1: Each letter (‘A’, ‘M’, or ‘T’) is evaluated only once. - Constraint 2: The function SWAP(TAM,i,j) is used only when it is…arrow_forwardConsider an input string TAM of letters ‘A’, ‘M’, and ‘T’. This string, which is given by the user, ends with ‘#’. It should be stored in a table (or array), called TAMUK. The number of each of these letters is unknown. We have a function, called SWAP(TAM,i,j), which places the ith letter in the jth entry of string TAM and the jth letter in the ith entry of TAM. Note that SWAP(TAM,i,j) is defined for all integers i and j between 0 and length(TAM)–1, where length(TAM) is the number of letters of TAM. 1. Using our algorithmic language, write an algorithm, called Sort_TAM, which sorts the letters in the array TAMUK in a way that all T’s appear first, followed by all A’s, and followed by all M’s. The algorithm Sort_TAM should have one parameter: The array TAMUK. Also, your solution is correct only if the following four constraints are satisfied: - Constraint 1: Each letter (‘A’, ‘M’, or ‘T’) is evaluated only once. - Constraint 2: The function SWAP(TAM,i,j) is used only when it is…arrow_forward
- IN PYTHON! Given an n×n matrix A and n×1 right-hand side b, write a function that carries out q iterations of the Gauss elimination outer loop (without pivoting), where q is an integer between 1 and n, and returns the resulting augmented matrix with all below-diagonal elements transformed to zero in the left-most q columns. ##The code format given below may help # def gaussq (A, b, q): '''Apply Gauss elimination (without pivoting) to first q columns of a given linear system Inputs: A, coefficient matrix, size n by n b, vector of constants, n by 1 q, number of columns to apply Gauss elimination to, an integer between 1 and n Output: Aa, augmented matrix with all below-diagonal elements transformed to zero in the left-most q columns, n by n+1 #to check the workarrow_forwardWrite a Matlab function named reflect_polynomial that will: [a] accept a univariate polynomial defined by a vector of polynomial coefficients (ordered by descending powers) as input, [b] plot the polynomial over a specified range, [c] reflect the polynomial about an arbitrary line in the x-y plane using matrix-vector multiplication, and [d] plot the reflected polynomial over the specified range. Your function should take the following inputs (in order): the vector of polynomial coefficients ordered by descending power, a vector specifying the plot range in the form [a b] where a<b, the vector of polynomial coefficients ordered by descending power that specifies the arbitrary axis of reflectionarrow_forwardA common way of implementing a max function is to look at the sign of a - b. In this case, we can't use a comparison operator on this sign, but we can use multiplication. Let k equal the sign of a - b such that if a - b >= 0, then k is 1. Else, k 0. Let q be the inverse of k.n implement the code:arrow_forward
- These two functions make way more sense now but I'm still confused about how I can write a function "newtinterp" out of these two. (Input arguments (x,y,z) where (xi, yi), i = 1,..., n+1, (interpolation data points) and z=(z1, ..., zm)(vectors containing m points on which we want to evaluate the interpolating polynomial)).arrow_forward3. Write a program to evaluate a polynomial \[ p(x)=c_{n} x^{n}+c_{n-1} x^{n-1}+\cdots+c_{2} x^{2}+c_{1} x+c_{0} \] and its derivative at a given pointt. The input is the row vectorcof coefficients of the polynomial arranged from highest to lowest power, and the numbert, and the two outputs arep(t)andp′(t). Computep(t)by first computing the row véctor \[ \left[t^{n}, t^{n-1}, \ldots, t^{2}, t, 1\right] \] and combine that with the vectorcto get the result. Computep′(t)by computing the coefficients of the derivative polynomial from the vectorc, and then evaluating that polynomial in the same way. Include some tests that provide evidence that your code produces the correct results. Please give proper explanation and typed answer only.arrow_forwardWrite a R function that takes two inputs: a vector y of n elements and a matrix X of n times k elements, where n should be greater than k, and returns two outputs: $X'X$ and $X'y$. Use the attr method to return the second output.arrow_forward
- Implement the following function, without using any data structure or #include <bits/stdc++.h> /* Given two vectors of chars, check if the two vectors are permutations of each other, i.e., they contains same values, in same or different order.e.g., V1=[‘a’,’b’,’a’] and V2=[‘b’,’a’,’a’] stores same multi-set of data points: i.e., both contains two ‘a’, and one ‘b’. e.g., V3=[‘a’,’c’,’t’,’a’] and V4=[‘a’,’c’,’t’] are not same multi-set. V3 contains two ‘a’s, while V4 has only one ‘a’. Note: when considering multiset, the number of occurrences matters. @param list1, list2: two vectors of chars @pre: list1, list2 have been initialized @post: return true if list1 and list2 stores same values (in same or different order); return false, if not. */ bool SameMultiSet (vector<char> list1, vector<char> list2) THIS IS NOT THE CORRECT SOLUTION / include headers #include <bits/stdc++.h> // deinfe the namespace using namespace std; // function fo rchecking same bool…arrow_forward(a) Write a function matrix_multiply(mat1, mat2) that takes two matrices and returns the result of the matrix multiplication between mat1 and mat2. If the two matrices are not compatible with multiplication, then None should be returned. (b) Write a function print_sums(list1, list2) that takes two equal-length lists of numbers and prints all the sums of the corresponding elements. Thus the first line is the sum of the first element of list1 and the first element of list2, the second line is the sum of the second elements, and so on.arrow_forwardConsider the function, f(n), defined by the following code int f(int n) { int r = 0; if ( n % 2 == 0 ) return 1; // when n is even while ( n > 1 ) { n = n – 3; r++; } return r; } From the definitions of big-Theta and little-oh: Prove or disprove that f(n) is Θ ( n ) 2. Prove or disprove that f(n) is o ( n^2 ) ( note: function f(n) as defined by the code, that is, the return value, and is not asking about the runtime of the code.)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
Definition of Array; Author: Neso Academy;https://www.youtube.com/watch?v=55l-aZ7_F24;License: Standard Youtube License