#include #include #define N 8192 #define FILE_A "matrix_A.bin" #define FILE_B "matrix_B.bin" void generate_and_save_matrix(const char *filename) { FILE *file = fopen(filename, "wb"); if (!file) { perror("無法打開檔案"); exit(EXIT_FAILURE); } double *row = (double *)malloc(N * sizeof(double)); if (!row) { perror("記憶體配置失敗"); exit(EXIT_FAILURE); } for (size_t i = 0; i < N; i++) { for (size_t j = 0; j < N; j++) { row[j] = (double)(rand() % 100) / 10.0; } fwrite(row, sizeof(double), N, file); } fclose(file); free(row); } int main() { generate_and_save_matrix(FILE_A); generate_and_save_matrix(FILE_B); printf("矩陣 A 和 B 已成功產生並存入 %s 和 %s\n", FILE_A, FILE_B); return 0; }