summaryrefslogtreecommitdiff
path: root/matmult.c
diff options
context:
space:
mode:
authorAlexander Pickering <alexandermpickering@gmail.com>2017-02-06 11:26:44 -0500
committerAlexander Pickering <alexandermpickering@gmail.com>2017-02-06 11:26:44 -0500
commit97a693d996c79fb2a008b19750d8bb45512e01a2 (patch)
tree6df17bfe7de7c59f7b1083828d71a91e61fae9fa /matmult.c
downloadengr0016-master.tar.gz
engr0016-master.tar.bz2
engr0016-master.zip
Inital commitHEADmaster
Diffstat (limited to 'matmult.c')
-rw-r--r--matmult.c80
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;
+}