transpose of a matrix java
for (int row = 0; row < matrix.length; row++) { for (int col = row; col < matrix[row].length; col++) { // Swap int data = matrix[row][col]; matrix[row][col] = matrix[col][row]; matrix[col][row] = data; } }
transpose of a matrix java
for (int row = 0; row < matrix.length; row++) { for (int col = row; col < matrix[row].length; col++) { // Swap int data = matrix[row][col]; matrix[row][col] = matrix[col][row]; matrix[col][row] = data; } }
transpose of a matrix in c++
#include <stdio.h> #define N 4 // This function stores transpose of A[][] in B[][] void transpose(int A[][N], int B[][N]) { int i, j; for (i = 0; i < N; i++) for (j = 0; j < N; j++) B[i][j] = A[j][i]; } int main() { int A[N][N] = { {1, 1, 1, 1}, {2, 2, 2, 2}, {3, 3, 3, 3}, {4, 4, 4, 4}}; int B[N][N], i, j; transpose(A, B); printf("Result matrix is \n"); for (i = 0; i < N; i++) { for (j = 0; j < N; j++) printf("%d ", B[i][j]); printf("\n"); } return 0; }
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us