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
C'ZT
Write a function that takes one input, a matrix X. Your function should modify X and return the modified version of X as an output. Assuming that X
has m rows and n columns:
When m is equal to n, modified X should be the same as X.
When m is greater than n, the modified version of X should be m x m. New columns should be added to the right of the original columns of X, with
each new element having a value that is one less than the element in the column to the left. For example, the matrix:
2 3
4 6
Would become:
2321
4 65 4
8987
1210
When n is greater than m, the modified version of X should be n x n. New rows should be added to the bottom of the original rows of X, with each new
element having a value that is one more than the element in the row above it. For example, the matrix:
2345
468 10
Would become
2345
4 6 1e
3791L
G8 10 12
2. Write a program to take input a 4 X 4 matrix using a user defined function and
print the output as follows:
Input:
1
2
4
5
6.
7
1
3
4
5
6.
Output:
7
5
11
13
15
13
9
1
3
11
7
9
11
9.
The value of every jh column of any ith row of the 2d-array is added with
the value of next column of ith row.
If the jh column represents the last column of the 2-d array, add the jh
column's item with the value of first column (where j = 0) of the inputted
2-d array.
R Programming - Rmarkdown:
1. Given two vectors x and y of equal length, in one line of code (in the function body), write a function find_max_logical() that will output a single logical vector that is TRUE at the indices where the maximum values in x and y are. For example, given the below vectors:
x <- c(Inf, 3, 2, 6, 99)
y <- c(12, 1, 0, 40, 5)
# You should return (without manually creating the vector with c()) c(TRUE, FALSE, FALSE, TRUE, FALSE)
# Noting that Inf and 40 are the max values of x and y respectively,
## at the 1st index of x and the 4th index of y.
Please test your functions on the following test inputs in your submission:
# test case 1: x = c(Inf, 3, 2, 6, 99), y = c(12, 1, 0, 40, 5)
# test case 2: x = 1:5, y = 1:5
# test case 3: x = c(1, 4, 9), y = c(1, 4, 2)
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
- Write a function called number_matrix(r,c) that takes two parameters r and c and PRINTS ON THE SCREEN a matrix of numbers as follows: 1 2 3 4 5 .... 2 3 4 5 6 .... 3 4 5 6 7 .... ... In this pattern, each row contains c numbers and there are r rows. For example, number_matrix(4,3) results in: 1 2 3 2 3 4 3 4 5 4 5 6arrow_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_forwardWrite a user-defined function that adds or subtracts two polynomials of any order. Name the function p=polyadd(p1,p2,operation). The first two input arguments p1 and p2 are the vectors of the coefficients of the two polynomials. (If the two polynomials are not of the same order, the function adds the necessary zero elements to the shorter vector.) The third input argument operation is a string that can be either ‘add’ or ‘sub’, for adding or subtracting the polynomials, respectively, and the output argument is the resulting polynomial. Try your code on several different inputs, and show the results.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_forwardWrite a function NewArray.m which takes two input arguments, m and n, and returns one output argument, A. The matrix A must have m rows and n columns. Create a (nested) for loop which computes A such that aij = = -i+j³. You must use a for loop for full credit. 022 wbsafa@ffalo.edustuse rate 9:19 PM EDT Вс C For example, if m= 2 and n = 3, then A= ck control ! 1 FI BO Q A @ 2 N 2 option F2 W S # 3 80 F3 X E H command D $ 4 a C R LL % 5 F + FS T V MacBook Air 6 G F6 tv 9 Y B & 7 H 1 6 25/ 34 U N 8 25). J F I ( 9 M K ** O ) 0 command : . ; F I { - [ 11 ? option 1 . I 1 delarrow_forwardWrite a user-defined function that adds or subtracts two polynomials of any order. Name the function p=polyadd(p1,p2,operation). The first two input arguments p1 and p2 are the vectors of the coefficients of the two polynomials. (If the two polynomials are not of the same order, the function adds the necessary zero elements to the shorter vector.) The third input argument operation is a string that can be either ‘add’ or ‘sub’, for adding or subtracting the polynomials, respectively, and the output argument is the resulting polynomial. Try your code on several different inputs, and show the results. Write this code for Matlab.arrow_forward
- I just want to Find the minimum path sum in matrix. The minimum path is sum of all elements from first row to last row where you are allowed to move only down or diagonally to left or right. You can start from any element in first row.Program should be in C language. First we ask the user for the number of rows and columns of the matrix, and then we generate a matrix of random numbers between 0 and 9 according to this number of rows and columns, and we find the smallest total path in this matrix. The rules are stated above. Example outputs : Enter number of rows (0 to exit): 3Enter number of columns: 5 9 7 8 [3] 88 6 [1] 2 34 7 5 [0] 8 Minimum sum:4 Enter number of rows (0 to exit): 5Enter number of columns: 7 6 4 8 9 1 [0] 33 0 5 9 [3] 4 23 0 8 1 [1] 3 34 2 0 7 [0] 9 37 5 9 9 3 [0] 3 Minimum sum: 4 Enter number of rows (0 to exit): 5Enter number of columns: 10 5 1 6 4 9 8 [0] 3 0 18 4 7 2 8 4 [2] 5 3 76 7 7 2 9 6 6 [0] 8 43 2 2 6 1 9 4 [2] 6 72 8 0 7 6 6 6 [1] 2 9 Minimum…arrow_forwardJohn is playing a dice game. The rules are as follows. Roll two dice. Add the numbers on the dice together. Add the total to your overall score. Repeat this for three rounds. But if you roll DOUBLES, your score is instantly wiped to 0 and your game ends immediately! Create a function which takes in a matrix as input, and return John's score after his game has ended (10 points). Example: diceGame([[1, 2], [3, 4], [1, 1]])→ 10 WRITE IN PYTHON PLEASEarrow_forwardPerform matrix multiplication of 2D array. The program should meet the matrix multiplication rule i.e. number of columns of first matrix should be equal to the number of rows of second matrix. The input of two matrices A and B is given by user. Use function approach to handle array multiplication.arrow_forward
- CAN YOU PLEASE RUN IT IN ONLINE GDB! C language. Write a program using pointers, which based on the adequate functions compute the sum, difference, dot product, or cross product of two vectors in Rn. Write a program using pointers, which based on the adequate functions, computes the sum, difference of multiplication of two matrices in Rm×n.arrow_forwardvector, or a matrix in the same way as described for rand function. EXERCISE I8 Generate a random integer between I and 10. Ask user to guess the number. If user's guess is incorrect, ask' to guess again until user gets it right. At this point, tell user that he guessed it correctly and print out the number of attempts it took for the correct guess. Output Samples >> exercisel8 Please guess an integer between 1 and 10: 5 Your guess is incorrect. Please try again: 2 You guessed it correctly in 2 attemptS >> >> exercise16 Please guess an integer between 1 and 10: 2 Your guess is incorrect. Please try again: 3 Your guess is incorrect. Please try again: 6 Your guess is incorrect. Please try again: 5 Your guess is incorrect. Please try again: 8 Your guess is incorrect. Please try again: 9 Your guess is incorrect. Please try again: 10 Your guess is incorrect. Please try again: 1 Your guess is incorrect. Please try again: 4 Your guess is incorrect. Please try again: 7 You guessed it correctly…arrow_forwardWrite a function that takes a vector of integers as an argument and returns a new vector with the same elements as the input vector, but with all odd elements replaced by their square root and all even elements replaced by their square. The function should use a loop and the modulo operator to determine whether an element is odd or even. To solve this problem, you will need to use a loop to iterate over the elements of the input vector, use the modulo operator to determine whether each element is odd or even, and use an if-else statement to determine what action to take for each element. This question requires knowledge of loops, the modulo operator, and if-else statements in R. It is a relatively advanced question and may be challenging for those who are not familiar with these concepts.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