Write a program (using functions) starting from directives to compute and display the transpose of a matrix of dimension m x n. [Note: Here, transpose of a matrix means the element at row r and column c in the original is placed at row c and column r of the transpose]. (Programming in C)

Answers

Answer 1

Answer:

#include <iostream>

#include <cstdlib>

using namespace std;

int m, n;

void transpose(int matrix[]){

  int transp[m][n];

  for (int i = 0; i < n; i++){

     for (int j = 0; j < m; j++){

        transp[j][i] = matrix[i][j];

        cout<< transp[j][i]<< " ";

     }

     cout<< "\n";

  }

}

int main(){

  cout<< "Enter the value for n: ";

  cin>> n;

  cout>> "Enter the value for m: ";

  cin>> m;

  int mymatrix[n][m];

  for (int i = 0; i < n; i++){

     for (int j = 0; j < m; j++){

        mymatrix[i][j] = (rand() % 50);

     }

  }

  transpose(mymatrix);

}

Explanation:

The C source code defined a void transpose function that accepts a matrix or a two-dimensional array and prints the transpose on the screen. The program gets user input for the row (n) and column (m) length of the arrays. The C standard library function rand() is used to assign random numbers to the array items.


Related Questions

Other Questions
How is power distributed in Brazil (Unitary, Confederation, or Federal)? In his bank account, Jean-Paul has a balance of $0.00His friend Albert has a bank balance of -$11.10Which friend's bank account has more debt?Choose 1 answer:A. Jean-PaulB. AlbertWhich friend's bank balance has a greater absolute value?Choose 1 answer:A. Jean-PaulB. Albert Argumentative Texts 8:Question 5Which statement does not represent an example of gender bias?Select one:A. In 2004, American men were more dedicated to their work than American womenwere.B. American women are better softball players than American men are.C.In 2004. American women earned more college degrees than American men earned.D.American men are better auto mechanics than American women are. which of these graphs represents a function Direct Democracy is made up of what two principles? (Must choose 2 answers)Consent of the GovernedMinority rulesMajority rulesRule of LawAll men voteLimited Government PLEASE HELP ME ! (i will give brainliest) Do you believe that anyone is able to murder in the right situation at the right time like if you daughter was about to be murdered but the only way to stop them is to murder them would you do it Competition occurs when organisms try to use the same limited resource. True or False Please help Ill give you guys brainiest!Thank youuuuuuu :)) What is the y coordinate of the solution When youre multiplying or dividing same sign numbers, what will your product or quotient be? True or False: The commutative property allows you to change the order of an addition problem and division problem. A bag contains exactly three red marbles, five yellow marbles and two blue marbles. If three marbles are drawn from the bag without replacement, what is the probability that all three will be the same color? Express your answer as a common fraction CAN SOMEONE HELP ME PLS Find the slope of the line (-4,4) (-3,-2) please solve 2x^2 -4x - 48 = 0 What is the most convenient way to study? Read this excerpt from "Eavesdropping" by Eudora Welty and answer the question.What they talked about, I have no idea . It was no doubt whatever a young married couple spending their first time privately in each others company in the long, probably harried day would talk about. It was the murmur of their voices, the back-and-forth, the unnoticed stretching away of time between my bedtime and theirs, that made me bask there at my distance. What I felt was not that I was excluded from them but that I was included, in and because of what I could hear in their voices and what I could see of their faces in the cone of yellow light under the brown-scorched shade.In this excerpt, Weltys diction best suggests she is writing to what possible audience?young married couples who want to improve their relationshipyoung people who readthoughtful readers interested in writing and literaturestudents in college Allison is the ______ of my two daughters while Rebecca is ______.Select one:a.more sensitive; sillierb.more sensitive; silliestc.most sensitive; sillierd.most sensitive; sillieste.sensitivest; more sillier Emma throws an object upward from a hill that is 64 feet high. The object has an initial velocity of 48 feet per second. The function y = -16x2 + 48x + 64 represents the height of the object, y, in terms of the time elapsed after the object is thrown, x.