参考代码:
#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 人评分
C语言程序设计教程(第三版)课后习题7.3 (C语言代码)浏览:637 |
C语言程序设计教程(第三版)课后习题10.3 (C语言代码)浏览:705 |
C语言训练-自由落体问题 (C语言代码)浏览:1769 |
C语言程序设计教程(第三版)课后习题9.3 (Java代码)浏览:1019 |
哥德巴赫曾猜测 (C语言代码)浏览:1129 |
C语言程序设计教程(第三版)课后习题5.4 (C语言代码)浏览:548 |
C语言程序设计教程(第三版)课后习题8.5 (C语言代码)浏览:953 |
C语言程序设计教程(第三版)课后习题3.7 (C语言代码)浏览:857 |
C语言程序设计教程(第三版)课后习题9.3 (C语言代码)浏览:2109 |
Cylinder (C语言描述,蓝桥杯)浏览:1272 |