Binod's Blog

Tag: Matrix Multiplication

Matrix Multiplication

by on Dec.14, 2010, under C & C++, DSA in C, Tutorial

#include<stdio.h>
#include<conio.h>
#define N 3
main(){
clrscr();
int a[N][N]={{1,2,3},{4,5,6},{7,8,9}};
int b[N][N]={{7,8,9},{4,5,6},{1,2,3}};
int result[N][N]={{0,0,0},{0,0,0},{0,0,0}};
int i,j,k;
//display matrix a
printf(“matrix A: \n”);
for(i=0;i<N;i++) {
for(j=0;j<N;j++) {
printf(“%d\t”,a[i][j]);
}
printf(“\n”);
}
printf(“matrix B: \n”);
//display matrix b
for(i=0;i<N;i++) {
for(j=0;j<N;j++) {
printf(“%d\t”,b[i][j]);
}
printf(“\n”);
}
//calculate result
for (i=0; i<N; i++) {
for (j=0; j<N; j++) {
for (k=0; k<N; k++) {
result[i][j] += a[i][k] * b[k][j];
}
}
}
printf(“matrix Result: \n”);
for(i=0;i<N;i++) {
for(j=0;j<N;j++) {
printf(“%d\t”,result[i][j]);
}
printf(“\n”);
}
getch();
return 0;
}

Leave a Comment :, , more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Blogroll

A few highly recommended websites...