Please use C !!!
Write a C function matrixTranspose that takes a two-dimensional array as its input argument then transposes its elements and prints the results.
Develop the matrixTranspose method with two different
methods:
1. Assume the matrix is a square matrix. This will make finding the
transpose a simple swapping of the arrays’ elements and it can be
done in place.
2. Generalize your function to work with any NxM matrix where N≠M.
You will need to properly handle dynamic memory allocation for
creating the transpose matrix inside the function.
Code:
#include<stdio.h>
void matrixTranspose(int *mat,int *trans,int r,int c){
int i,j,k=0;
for(i=0;i<r;i++){
for(j=0;j<c;j++){
trans[j*r+i]=mat[k++];
//assigning main matrix values to transposed
//matrix with transposed indexes.
}
}
}
int main(){
int i,j,r,c;
printf("matrix size: ");
scanf("%d%d",&r,&c);
//taking row and column size from user
int mat[r][c],trans[c][r];
//declaring
matrix and transpose matrix with reverse dimensions
printf("enter matrix:\n");
for(i=0;i<r;i++){
for(j=0;j<c;j++){
scanf("%d",&mat[i][j]);
//taking values for main matrix from user
}
}
matrixTranspose(mat,trans,r,c);
//passing addresses of main
matrix and transpose matrix to matrixTranspose() function
printf("Transpose matrix is:\n");
for(i=0;i<c;i++){
for(j=0;j<r;j++){
printf("%d
",trans[i][j]);
//after completion of
function calling main matrix transposed values strored in transpose
matrix, printing those values.
}
printf("\n");
}
}
Screenshots:
output:
Please use C !!! Write a C function matrixTranspose that takes a two-dimensional array as its...
Write a function in C# called show2D. The function should accept a two-dimensional array as an argument and display its contents on the screen. The function should work with any of following arrays: int hours[3][8]; int stamps[5][8]; int cities[14][8];
C++ Write a program to calculate the sum of two matrices that are stored inside two-dimensional arrays. Your program should include three functions: one for getting input data, one for calculating the sum of matrices, and one for printing the result. a) Function inputMatrix: This Function prompts the user to enter the data and stores data inside two-dimensional array. b) Function addMatrices: This function calculatesthe sum result of two matrices. c) Function printMatrix: This function prints the matrix to screen....
Q 3-) (30 points) Write a C program (MAIN function) and a FUNCTION to create and print the transpose of a two- dimensional array. Within C program (the MAIN function); Declare a two- dimensional 3X2 integer array A and initialise with the values (1,2), (3,4), (5,6), declare also a two-dimensional 2X3 integer array B and initialise it with zero. Call the FUNCTION and pass arrays A and B to the FUNCTION as arguments. Print the array A and its transpose....
array function • Create a function called show2D. • This function should accept a two-dimensional array as parameter and display its contents that are odd numbers on the screen. • This function should work with any of the following arrays of different sizes: int hours[3][9]; int stamps[7][9]; int cities[15][9]; • Write a demo program to show how to use the function show2D. this is c++ program Task 2: Array functions • Create a function called show2D. • This function should...
C++.Write the body of a function that returns the sum of all elements in a two-dimensional array passed to it as an argument. Declare and initialize all needed variables. int arraySum(const int numbers[][COLS], int rows) { }
-Create a function output() in C that takes the pointer to the array and its size and prints the arrays' contests. (malloc format) (function prototype : void output(int *arrayPtr, int size); -Create a function check() in C that takes the pointer to the array and a number and checks if the number is in the array. If the number is in the array, returns the index of the element of the array holding the number. Otherwise, returns -1.
Array processing Create a program that processes two-dimensional array according to task variant Additional requirements 1. 2. 3. 4. Input dimensions of array form keyboard (use dynamic memory allocation) Fill array with random numbers in range R. Processing of array should be implemented as function (using indices). Displaying the content of array should be implemented as function (using pointers) 5 12 8 2 8 3 3 16 1 22 215 34 0 11 88 13 22 6 5 81 76...
Write a C++ function that takes a two-dimensional array and a row index. The function should return the multiplication of all the values in the row. Write a main () program to test the function. Student Note: Please solve the question as simple as you can.
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”,...
Write a C++ function printArray(A, m, n) that prints an m × n two dimensional array A of integers, declared to be “int** A,” to the standard output. Each of the m rows should appear on a separate line.