diff options
| author | Alexander Pickering <alexandermpickering@gmail.com> | 2017-02-06 11:26:44 -0500 |
|---|---|---|
| committer | Alexander Pickering <alexandermpickering@gmail.com> | 2017-02-06 11:26:44 -0500 |
| commit | 97a693d996c79fb2a008b19750d8bb45512e01a2 (patch) | |
| tree | 6df17bfe7de7c59f7b1083828d71a91e61fae9fa /transpose.c | |
| download | engr0016-97a693d996c79fb2a008b19750d8bb45512e01a2.tar.gz engr0016-97a693d996c79fb2a008b19750d8bb45512e01a2.tar.bz2 engr0016-97a693d996c79fb2a008b19750d8bb45512e01a2.zip | |
Diffstat (limited to 'transpose.c')
| -rw-r--r-- | transpose.c | 65 |
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; +} |
