/*
* File Name: Innerproduct.c
* Author: MH
* Since 2011/03/21
* Toolkit: Dev C++
*/
# include <stdlib.h>
# include <stdio.h>
int main(){
int i, j, k;
int array1[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; //array[row][column]
int array2[3][3] = {{2, 3, 4}, {5, 6, 7}, {8, 9, 1}};
int array3[3][3] = {0};
printf("A = \n");
for(i=0; i<3; i++){
for(j=0; j<3; j++){
printf("%-3d", array1[i][j]);
}
printf("\n");
}
printf("\nB = \n");
for(i=0; i<3; i++){
for(j=0; j<3; j++){
printf("%-3d", array2[i][j]);
}
printf("\n");
}
printf("\n\nA・B =\n");
for(i=0; i<3; i++){
for(j=1; j<3; j++){
for(k=1; k<=3; k++){
array3[i][j] = array3[i][j] + array1[i][k] * array2[k][j];
// array1: from left to right, from top to bottom
// array2: from top to bottom, from left to right
}
printf("%-5d", array3[i][j]);
}
printf("\n\n");
}
printf("\n");
system("Pause");
return 0;
}
搜尋此網誌
[C/C++][矩陣內積]
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言