diff --git a/task3.cpp b/task3.cpp new file mode 100644 index 0000000..d43d6aa --- /dev/null +++ b/task3.cpp @@ -0,0 +1,60 @@ +#include +#include +#include + +#define SIZE 102 +void matmul(float** A, float** B, float** C, int n) +{ + for (int i = 0; i < n; ++i) + { + for (int j = 0; j < n; ++j) + { + C[i][j] = 0; + for (int k = 0; k < n; ++k) + { + C[i][j] += A[i][k] * B[k][j]; + } + } + } +} +int main() +{ + srand(time(NULL)); + + // 分配矩阵内存 + float** A = (float**)malloc(SIZE * sizeof(float*)); + float** B = (float**)malloc(SIZE * sizeof(float*)); + float** C = (float**)malloc(SIZE * sizeof(float*)); + for (int i = 0; i < SIZE; ++i) + { + A[i] = (float*)malloc(SIZE * sizeof(float)); + B[i] = (float*)malloc(SIZE * sizeof(float)); + C[i] = (float*)malloc(SIZE * sizeof(float)); + } + + //初始化矩阵数据 + for (int i = 0; i < SIZE; i++) + { + for(int j=0;j