参考代码:
#include<iostream> using namespace std; #define MX 50 int ia[MX][MX] = {}; int ib[MX][MX] = {}; int ab[MX][MX] = {}; size_t m, n; void matrix_mul(int arr[][MX],int arr1[][MX],int arr2[][MX]) { for (size_t i = 0; i != m; ++i) { for (size_t j = 0; j != m; ++j) { for (size_t k = 0; k != m; ++k) arr[i][j] += arr1[i][k] * arr2[k][j]; } } } void matrix_mi(int n) { if (n == 0) { for (size_t i = 0; i != m; ++i) { for (size_t j = 0; j != m; ++j) { ab[i][j] = ib[i][j]; } } } else { while (n != 0) { for (size_t i = 0; i != m; ++i) { for (size_t j = 0; j != m; ++j) { ab[i][j] = 0; } } matrix_mul(ab, ia, ib); for (size_t i = 0; i != m; ++i) { for (size_t j = 0; j != m; ++j) { ib[i][j] = ab[i][j]; } } n--; } } } int main() { cin >> m >> n; for (size_t i = 0; i != m; ++i) { for (size_t j = 0; j != m; ++j) { cin >> ia[i][j]; if (i == j) { ib[i][j] = 1; } } } matrix_mi(n); for (size_t i = 0; i != m; ++i) { for (size_t j = 0; j != m; ++j) cout << ab[i][j] << " "; cout << endl; } return 0; }
0.0分
10 人评分
简洁的代码浏览:1474 |
C语言程序设计教程(第三版)课后习题6.3 (Java代码)浏览:695 |
C语言程序设计教程(第三版)课后习题7.4 (Java代码)浏览:873 |
C语言程序设计教程(第三版)课后习题8.4 (Java代码)浏览:788 |
弟弟的作业 (C++代码)浏览:1342 |
C语言训练-求具有abcd=(ab+cd)2性质的四位数 (C语言代码)浏览:619 |
不会做的浏览:954 |
2006年春浙江省计算机等级考试二级C 编程题(2) (C语言代码)浏览:674 |
C语言程序设计教程(第三版)课后习题6.11 (C语言代码)浏览:565 |
简单的for循环浏览:1495 |