summaryrefslogtreecommitdiff
path: root/transpose.c
diff options
context:
space:
mode:
Diffstat (limited to 'transpose.c')
-rw-r--r--transpose.c65
1 files changed, 65 insertions, 0 deletions
diff --git a/transpose.c b/transpose.c
new file mode 100644
index 0000000..32c769b
--- /dev/null
+++ b/transpose.c
@@ -0,0 +1,65 @@
+/*File: transpose.c The transpose of matrix A is obtained by interchanging the rows and columns. */
+#include <stdio.h>
+
+#define M 10
+#define N 20
+
+int main()
+{
+
+ double a[M][N], b[N][M];
+ int row,col;
+
+ for(row=0;row<M;row++)
+ {
+ for(col=0;col<N;col++)
+ {
+ a[row][col] = row*col;
+ }
+ }
+
+ for(row=0;row<M;row++)
+ {
+ for(col=0;col<N;col++)
+ {
+ b[col][row]=a[row][col];
+ }
+ }
+
+ printf("Matrix a is\n");
+ for(row=0;row<M;row++)
+ {
+ for(col=0;col<N;col++)
+ {
+ printf("%3i ",(int)a[row][col]);
+ }
+ printf("\n");
+ }
+
+ printf("\nMatrix b is \n");
+ for(row=0;row<N;row++)
+ {
+ for(col=0;col<M;col++)
+ {
+ printf("%3i ",(int)b[row][col]);
+ }
+ printf("\n");
+ }
+
+ printf("\nAn identity matrix of size %i\n",M);
+ int ident[M][M];
+ for(row=0;row<M;row++)
+ {
+ ident[row][row] = 1;
+ }
+
+ for(row=0;row<M;row++)
+ {
+ for(col=0;col<M;col++)
+ {
+ printf("%i ",ident[row][col]);
+ }
+ printf("\n");
+ }
+ return 0;
+}