Question

Q 3-) (30 points) Write a C program (MAIN function) and a FUNCTION to create and print the transpose of a two- dimensional ar
0 0
Add a comment Improve this question Transcribed image text
Answer #1

code:

#include <stdio.h>
int main()
{
int A[3][2] = { {1, 2}, //initialising 3*2 matrix
{3, 4},
{5, 6},
};
  
int B[2][3], i, j; //initialising B matrix (2*3)
printf("The initial matrix is >>>> \n");
for (i = 0; i < 3; i++) //loop to print matrix A
{
for (j = 0; j < 2; j++)
{
printf("%d ", A[i][j]); //printing final matrix
}
printf("\n");
}
transposeMatrix(A, B); //calling function
printf("The resultant transpose matrix is >>>> \n");
for (i = 0; i < 2; i++) //loop to print final matrix
{
for (j = 0; j < 3; j++)
{
printf("%d ", B[i][j]); //printing final matrix
}
printf("\n");
}
return 0;
}
void transposeMatrix(int A[3][2], int B[2][3]) //called function
{
int i, j;
for (i = 0; i < 2; i++) //code to transpose matrix
for (j = 0; j < 3; j++)
B[i][j] = A[j][i];   
}

11 1 #include <stdio.h> 2 int main() 3- { 4 int A[3][2] = { {1, 2}, //initialising 3*2 matrix 5 {3, 4}, 6 {5, 6}, 7 }; 8 9 in

31 void transposeMatrix(int A[3][2], int B[2][3]) //called function 32 { 33 int i, j; 34 for (i = 0; i < 2; i++) //code to tr

output:

The initial matrix is >>>> 1 2 3 4 5 6 The resultant transpose matrix is >>>> 1 3 5 2 4 6

Add a comment
Know the answer?
Add Answer to:
Q 3-) (30 points) Write a C program (MAIN function) and a FUNCTION to create and...
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
  • I need to create a c++ print function that takes a vector of values ex: <1...

    I need to create a c++ print function that takes a vector of values ex: <1 2 3 4 5 6> and prints it in the correct way with the given dimensions. Example 2x3 = [[1,2,3],[4,5,6]] or 3x2 = [[1,2],[3,4],[5,6]]. To make this even more difficult there can be 3 dimensional matrixs. For example for <1 2 3 4 5 6 7 8 9 10 11 12> with dimensions depthXheightXwidth: 2x3x2 = [[[1,2],[3,4],[5,6]],[[7,8],[9,10],[11,12]]]. The depth height and width could be...

  • C++ Program Int Main First Please Write one program that does the following: 1.       1.   Ask the...

    C++ Program Int Main First Please Write one program that does the following: 1.       1.   Ask the user for ten (10) grades, and store the data in an array.  Compute the average of all the grades.  Print the original ten grades and the average. a.       Declare an integer array with the name of “grades” of size 10 in the main function. b.      Create a function called “getGrades” that prompts the User for the grades and puts them in an integer array.                                                                i.      The function will receive...

  • In this lab, you will create one class named ArrayFun.java which will contain a main method...

    In this lab, you will create one class named ArrayFun.java which will contain a main method and 4 static methods that will be called from the main method. The process for your main method will be as follows: Declare and create a Scanner object to read from the keyboard Declare and create an array that will hold up to 100 integers Declare a variable to keep track of the number of integers currently in the array Call the fillArray method...

  • Write a program that will do the following. The main function should ask the user how...

    Write a program that will do the following. The main function should ask the user how many numbers it will read in. It will then create an array of that size. Next, it will call a function that will read in the numbers and fill the array (fillArray). Pass the array that was made in themain function as a parameter to this function. Use a loop that will read numbers from the keyboard and store them in the array. This...

  • Write a C program (not C++) that calls a function to multiply a matrix (two dimensional...

    Write a C program (not C++) that calls a function to multiply a matrix (two dimensional array). The main program should ask the user to enter an integer that will be used as the matrix “adder” and then call the function. The function should perform a matrix increment (every element of the array is incremented by the same value) and assign the result to another array. The function should be flexible enough to work with any array size and “adder”,...

  • Use C: 3. In function main, declare a two-dimensional integer array with 5 rows and 4...

    Use C: 3. In function main, declare a two-dimensional integer array with 5 rows and 4 columns. Call the following functions from function main. Call a function createArray to seed the random number generator and to fill the two-dimensional array with random integers between -20 and +20. Parameters for this function should be the array and the number of rows and columns). Call a function signs to count the number of positive values, number of negative values and number of...

  • Must use JOPTIONPANE. Using arrays and methods create a JAVA program. Create a java program that...

    Must use JOPTIONPANE. Using arrays and methods create a JAVA program. Create a java program that holds an array for the integer values 1-10. Pass the array to a method that will calculate the values to the power of 2 of each element in the array. Then return the list of calculated values back to the main method and print the values

  • Use c++ as programming language. The file needs to be created ourselves (ARRAYS) Write a program...

    Use c++ as programming language. The file needs to be created ourselves (ARRAYS) Write a program that contains the following functions: 1. A function to read integer values into a one-dimensional array of size N. 2. A function to sort a one-dimensional array of size N of integers in descending order. 3. A function to find and output the average of the values in a one dimensional array of size N of integers. 4. A function to output a one-dimensional...

  • 4. Write a C program that will perform the following: a. In the main program enter...

    4. Write a C program that will perform the following: a. In the main program enter 2 integer numbers. If the first number is less than the second number call the function happy(). Otherwise give a warning message that the function is not performed. b. Define a function happy() that will request from the user to enter 10 integer numbers to one dimensional array A. The function will find and return how many numbers are above 5.

  • Write a C function named add with the following parameters: three float arrays a, b and c, each of the three arrays is...

    Write a C function named add with the following parameters: three float arrays a, b and c, each of the three arrays is a two dimensional array. The function should add the first two arrays a and b (entry by entry), storing the results in the third array c. In the main function, call the add function with appropriate values. The main function should print the sum of the two arrays stored in the third array. Sample run: float al...

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