From fa45c4f47661b03c6581b00bcaf81f6c5542fb01 Mon Sep 17 00:00:00 2001 From: pv3e4i5aj Date: Sat, 23 Nov 2024 18:08:35 +0800 Subject: [PATCH] Add task3.cpp --- task3.cpp | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 task3.cpp 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