From 636cd629944915562b49162c6d1922cff42d1275 Mon Sep 17 00:00:00 2001 From: Aakrisht69 <115407142+Aakrisht69@users.noreply.github.com> Date: Thu, 20 Oct 2022 00:29:23 +0530 Subject: [PATCH] Create Transpose.cpp Hacktoberfest Submission. #13 --- Cpp/Transpose.cpp | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 Cpp/Transpose.cpp diff --git a/Cpp/Transpose.cpp b/Cpp/Transpose.cpp new file mode 100644 index 0000000..3e82146 --- /dev/null +++ b/Cpp/Transpose.cpp @@ -0,0 +1,37 @@ +#include +using namespace std; +#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]; +} + +// Driver code +int main() +{ + int A[N][N] = { { 1, 1, 1, 1 }, + { 2, 2, 2, 2 }, + { 3, 3, 3, 3 }, + { 4, 4, 4, 4 } }; + + // Note dimensions of B[][] + int B[N][N], i, j; + + // Function call + transpose(A, B); + + cout << "Result matrix is \n"; + for (i = 0; i < N; i++) { + for (j = 0; j < N; j++) + cout << " " << B[i][j]; + + cout << "\n"; + } + return 0; +}