diff options
Diffstat (limited to 'matmult.c')
| -rw-r--r-- | matmult.c | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/matmult.c b/matmult.c new file mode 100644 index 0000000..d1b2f2c --- /dev/null +++ b/matmult.c @@ -0,0 +1,80 @@ +/* File: matmult.c + Multiplication of two matricies*/ +#include <stdio.h> + +#define M 10 +#define N 20 +#define P 30 + +int main() +{ + double a[M][N]; + double b[N][P]; + double c[M][P]; + int i; + int j; + int k; + + int pop1,pop2; + for(pop1=0;pop1<M;pop1++) + { + for(pop2=0;pop2<N;pop2++) + { + a[pop1][pop2] = pop1+pop2; + } + } + + for(pop1=0;pop1<M;pop1++) + { + for(pop2=0;pop2<P;pop2++) + { + b[pop1][pop2] = pop1*pop2; + } + } + + for(i=0;i<M;i++) + { + for(j=0;j<P;j++) + { + c[i][j] = 0; + for(k=0;k<N;k++) + { + c[i][j] += a[i][k]*b[k][j]; + } + } + } + + printf("Matrix a is\n"); + int l,m; + + for(l = 0;l<M;l++) + { + for(m = 0; m<N;m++) + { + printf("%3i ",(int)a[l][m]); + } + printf("\n"); + } + + printf("\nMatrix b is\n"); + for(l = 0;l<M;l++) + { + for(m = 0; m<N;m++) + { + printf("%3i ",(int)b[l][m]); + } + printf("\n"); + } + + printf("\nMatrix c is\n"); + for(l = 0;l<M;l++) + { + for(m = 0; m<N;m++) + { + printf("%5i ",(int)c[l][m]); + } + printf("\n"); + } + + return 0; +} |
