ZZULIOJ 1127: matrix product

1127: matrix product

Title Description

Computes the product of two matrices A and B.

Entry

The first line of three positive integers m, p and n, 0 <= m, n , p <= 10, A represents a matrix of m rows and p columns, the matrix B is p rows and n columns;
next row is m matrix A content, each row integers p, separated by spaces;
final content of p rows of matrix B, n integers each row, separated by spaces.

Export

Product matrix output: output accounted for m rows, each row of n data, separated by a space.

Sample input Copy

2 3 4

1 0 1
0 0 1

1 1 1 3
4 5 6 7
8 9 1 0

Sample output Copy

9 10 2 3
8 9 1 0

C

#include<stdio.h>
int main()
{
	int m,p,n,i,j,k,a[10][10],b[10][10],c[10][10];
	scanf("%d%d%d",&m,&p,&n);
	for(i=0;i<m;i++)
		for(j=0;j<p;j++)
			scanf("%d",&a[i][j]);
	for(i=0;i<p;i++)
		for(j=0;j<n;j++)
			scanf("%d",&b[i][j]);
	for(i=0;i<m;i++)
		for(j=0;j<n;j++){
			c[i][j]=0;
			for(k=0;k<p;k++)
				c[i][j]=c[i][j]+a[i][k]*b[k][j];
			printf("%d%c",c[i][j],j==n-1?'\n':' ');
		}
	return 0;
}
Published 10 original articles · won praise 0 · Views 181

Guess you like

Origin blog.csdn.net/qq_45845830/article/details/104091844