#include <stdio.h>
const int M = 5;
const int N = 4;
const int L = 3;
void main(){
int i = 0,j = 0,k;
FILE *fp1,*fp2;
int matr1[M][N],matr2[N][L],matr3[M][L];
//从文本文件1中读入矩阵
printf("The array 1 is :\n");
if((fp1 = fopen("../array1.txt","r"))==NULL)
{
printf("Can not open file!\n");
}
for (i=0;i<M;i++){
for (j=0;j<N;j++){
fscanf(fp1,"%d",&matr1[i][j]);
}
}
for (i=0;i<M;i++){
for (j=0;j<N;j++){
printf("%d\t",matr1[i][j]);
}
printf("\n");
}
fclose(fp1);
//从文本文件2中读入矩阵
printf("The array 2 is:\n");
if((fp2 = fopen("../array2.txt","r"))==NULL)
{
printf("Can not open file!\n");
}
for (i=0;i<N;i++){
for (j=0;j<L;j++){
fscanf(fp2,&
文件读写方式实现矩阵相乘
最新推荐文章于 2021-05-17 14:01:53 发布
该程序从两个文本文件中读取矩阵,然后计算它们的乘积,并将结果写入新文件。通过fopen打开文件,使用fscanf读取矩阵元素,fprintf输出结果并使用fclose关闭文件。
摘要由CSDN通过智能技术生成