码迷,mamicode.com
首页 > 其他好文 > 详细

矩阵乘法

时间:2015-02-26 16:40:45      阅读:122      评论:0      收藏:0      [点我收藏+]

标签:java   蓝桥杯   

技术分享



import java.util.*;
import java.io.*;


public class 矩阵乘法 {
public static void main(String[] args) {
Scanner in = new Scanner(new BufferedInputStream(System.in));
int m = in.nextInt();
int s = in.nextInt();
int n = in.nextInt();
int[][] a = new int[m][s];
int[][] b = new int[s][n];
for (int i = 0; i < m; i++) {
for (int j = 0; j < s; j++) {
a[i][j] = in.nextInt();
}
}
for (int i = 0; i < s; i++) {
for (int j = 0; j < n; j++) {
b[i][j] = in.nextInt();
}
}
int[][] c = new int[m][n];
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
c[i][j] = 0;
for (int k = 0; k < s; k++) {
c[i][j] += a[i][k] * b[k][j];
}
System.out.print(c[i][j] + " ");
}
System.out.println();
}
}
}

矩阵乘法

标签:java   蓝桥杯   

原文地址:http://blog.csdn.net/a736933735/article/details/43953627

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!