第1行:1个数N,表示矩阵的大小(2 <= N <= 100) 第2 - N + 1行,每行N个数,对应M1的1行(0 <= M1[i] <= 1000) 第N + 2 - 2N + 1行,每行N个数,对应M2的1行(0 <= M2[i] <= 1000)
输出共N行,每行N个数,对应M1 * M2的结果的一行。
2 1 0 0 1 0 1 1 0
0 1 1 0
#include <stdio.h> #define MAX 105 short M1[MAX][MAX],M2[MAX][MAX]; int main(){ //freopen("C:\\in.txt","r",stdin); int N; scanf("%d",&N); short *p1,*p2,*end; short i,j; for( i = 0; i < N; ++i ) for( p1 = M1[i], end = p1 + N; p1 != end; ++p1 ) scanf( "%hd", p1 ); for( j = 0, end = M2[N]; j < N; ++j ) for( p2 = M2[0] + j; p2 < end; p2 += MAX ) scanf( "%hd", p2 ); for(i=0;i<N;i++) for(j=0;j<N;j++){ int sum=0; for(p1=M1[i],p2=M2[j],end=p1+N;p1<end;++p1,++p2)sum+=(*p1)*(*p2); printf("%d%c",sum,j==N-1?‘\n‘:‘ ‘); } return 0; }
原文:http://blog.csdn.net/starcuan/article/details/19702273