Question

1) 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 Nob equal to the value of Mb,a for all relevant values of a and b. Write a function transposeMatrix) that takes as an argument a 4 x 5 matrix and a 5 x 4 matrix. Have the function transpose the 4 x 5 matrix and store the results in the 5 x 4 matrix. Also write a main() routine to test the function. See example below Matrix N (transposed) 1 6 Matrix M (original) 3 6 7 8 9 10 11 12 1314 15 16 17 18 19 20 4. 11 16 3 8 13 18 4 914 19 5 10 15 20

Stdio.h format.
Proper commenting please.
Needs to be able to be saved as a .C file.
Thanks in advance.
Please do not copy and paste any of the other answers already on this site as they do not work. If you can't do it please don't answer my question.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <stdio.h>

void transposeMatrix(int M[4][5], int N[5][4])

{

// variable i will access each row index 1 by 1

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

{

// var j will access all column index for each row i

for (int j = 0; j < 5; ++j)

{

// place 1st row of M into 1st column of N

N[j][i] = M[i][j];

}

}

}

int main(int argc, char const *argv[])

{

// define array M(4x5) abd initilized it

int M[4][5]={

{1, 2, 3, 4, 5},

{6, 7, 8, 9, 10},

{11, 12, 13, 14, 15},

{16, 17, 18, 19, 20}

};

// define array N[5x4] and initilizedit with 0

int N[5][4] = {0};

// call transposeMatrix function

transposeMatrix(M, N);

// print original matrix M

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

{

for (int j = 0; j < 5; ++j)

{

printf("%4d ",M[i][j]);

}

printf("\n");

}

printf("\n\n");

//print transpose matrix N

for (int i = 0; i < 5; ++i)

{

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

{

printf("%4d ",N[i][j]);

}

printf("\n");

}

return 0;

}

-/Desktop/transposeMatrix.c -Sublime Text (UNREGISTERED) File Edit Selection Find View Goto Tools Project Preferences Help #include «stdio.h 2 void transposeMatrix(int M[4][5], int N[5][4]) ram@Angel:-/Desktop File Edit View Search Terminal Help I variable i wilt access each row index 1 by1 for (inti-e; i<4; ++i) ram@Angel:-s cd Desktop/ I var j will access all column index for each row i for (int j ; j <5; ++j) ram@Angel:-/Desktop$ gcc transposeMatrix.c ram@Angel:~/Desktop$ ./a.out 1 2 345 9 10 11 12 13 14 15 16 17 18 19 20 10 place 1st row of M into 1st column of N 12 13 14 15 int main(int argc, char const *argv[l) 16 1 6 11 16 2 7 12 17 8 13 18 9 14 19 5 10 15 20 ramGAngel:-/Desktops /define array M(4x5) abd initilized it int M[41[51- 18 19 20 1, 2, 3, 4, 5) (6, 7, 8, 9, 10), (11, 12, 13, 14, 15, 16, 17, 18, 19, 20 t: 23 24 25 26 27 28 // define array N[5x4] and initilizedit with θ int N[5][4] -(0) call transposeMatrix function transposeMatrix(M, N); // print original matrix м for (inti-e; i<4; ++i) 30 31 32 for (int j-e;j <5;++j) printf(%4d ,M[i][j]); 34 35 36 printf (\n); printf(In\n); //print transpose matrix N 38 Line 38, Column 31 Tab Size: 4

Add a comment
Know the answer?
Add Answer to:
Stdio.h format. Proper commenting please. Needs to be able to be saved as a .C file....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 2. Cut and file with yower namme on the Sirst pae to Biacsbownd (holkdert Course . Upload the wor...

    help with all but priority on last 2 questions 2. Cut and file with yower namme on the Sirst pae to Biacsbownd (holkdert Course . Upload the word file with ower o1. (25 pts) Matrix A (6x6) is defined as 35 1 6 26 19 24 3 32 7 21 23 25 31 9 2 22 27 20 8 28 33 17 10 15 0 534 12 14 16 4)36 29 13 18 11 Write a script to find the...

  • Question 1 a. Define the following matrices in a script file (M-file), ? = ( 8...

    Question 1 a. Define the following matrices in a script file (M-file), ? = ( 8 9 10 11; 23 9 16 15 ;11 12 3 6; 1 2 8 9 ) ? = ( 2 21 7 15; 12 4 8 22; 23 9 5 13; 23 4 21 22) ℎ = (4 9 12 15) b. Add suitable lines of codes to the M-file to do the following. Each of the following points should be coded in only...

  • Diagonal Difference HackerRank Pseudocode and C++: Given a square matrix, calculate the absolute difference between the...

    Diagonal Difference HackerRank Pseudocode and C++: Given a square matrix, calculate the absolute difference between the sums of its diagonals. Function Description Complete the diagonalDifference function described below to calculate the absolute difference between diagonal sums. diagonalDifference( integer: a_size_rows, integer: a_size_cols, integer array: arr) Parameters: a_size_rows: number of rows in array a_size_cols: number of columns in array a: array of integers to process Returns: integer value that was calculated Constraints -100 < = elements of the matrix < = 100...

  • C Programming #include <stdio.h> #include <stdlib.h> #include <time.h> // These defines do a text repl...

    C Programming #include <stdio.h> #include <stdlib.h> #include <time.h> // These defines do a text replacement // everytime the string 'ROWS' and 'COLUMNS' // are found in this specific source file. // You can play with these values. #define ROWS 5 #define COLUMNS 5 /* ============= Tutorial on Graph format ============ You are given a randomly generated graph that looks of the form: 0 0 1 1 1 1 0 0 1 1 0 1 0 1 1 1 0 0...

  • C++ how can I fix these errors this is my code main.cpp #include "SpecialArray.h" #include <...

    C++ how can I fix these errors this is my code main.cpp #include "SpecialArray.h" #include <iostream> #include <fstream> #include <string> using namespace std; int measureElementsPerLine(ifstream& inFile) {    // Add your code here.    string line;    getline(inFile, line);    int sp = 0;    for (int i = 0; i < line.size(); i++)    {        if (line[i] == ' ')            sp++;    }    sp++;    return sp; } int measureLines(ifstream& inFile) {    // Add your code here.    string line;    int n = 0;    while (!inFile.eof())    {        getline(inFile,...

  • Please code in C++. link to continue the code is this below or you can make...

    Please code in C++. link to continue the code is this below or you can make your own code if you wish(fix any mistakes if you think there are any in it): cpp.sh/3qcekv 3. Submit a header file (project3.h), a definition file (project3.cpp), a main file (main.cpp), and a makefile to compile them together. Make sure to run the command make and produce an application file and include it with your submission. For this project, you are required to create...

  • Problem 1 Write your code in the file MatrixOps.java. . Consider the following definitions from matrix...

    Problem 1 Write your code in the file MatrixOps.java. . Consider the following definitions from matrix algebra: A vector is a one-dimensional set of numbers, such as [42 9 20]. The dot product of two equal-length vectors A and B is computed by multiplying the first entry of A by the first entry of B, the second entry of A by the second entry of B, etc., and then summing these products. For example, the dot product of [42 9...

  • Could you do that in C language? Here is the code which we got #include <stdio.h>...

    Could you do that in C language? Here is the code which we got #include <stdio.h> #define MAX_SIZE 20 // function definitions void displaySpiral(int matrix[][MAX_SIZE], int size); void displayMatrix(int matrix[][MAX_SIZE], int size); int takeInput(int inputMatrix[][MAX_SIZE]); int main() { int matrix[MAX_SIZE][MAX_SIZE]; int matrixSize = takeInput(matrix); printf("Displaying the whole matrix:\n"); fflush(stdout); displayMatrix(matrix, matrixSize); printf("Now, displaying the matrix in a spiral way:\n"); fflush(stdout); displaySpiral(matrix, matrixSize); return 0; } // already implemented for you int takeInput(int inputMatrix[][MAX_SIZE]) { int size; printf("What is the size...

  • Please explain answer :D Question 5 (5 marks] Consider the syntactically correct C code below, which...

    Please explain answer :D Question 5 (5 marks] Consider the syntactically correct C code below, which is missing a function print_diagonal include <stdio.h> • typedef int Table(100) (100); */• print diagonal (T, n) . Given a Table T, which will have n rows and n columns, print all of the 1 entries on the main diagonal of T (that is, entries whose row number and column number are equal). Remember to print a newline at the end. / ► /...

  • Use the create_matrix function from the tutorial file, along with a function a (i, j) (which...

    Use the create_matrix function from the tutorial file, along with a function a (i, j) (which you will have to create) to produce the following 17 × 17 matrix. Then find its determinant. 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 5 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 6 6 1 1 1 1 1 1 1 1 1 1 1...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT