当前位置:网站首页>How to write an augmented matrix into TXT file

How to write an augmented matrix into TXT file

2022-07-07 22:06:00 51CTO

Write a 398 That's ok ,399 Columns of the matrix


#include<iostream>


using namespace std;

int main()

{

float arr1[450];

float c=1.0;

float b=2.0;

int i=0,j=0;

   FILE *fp;

for(i=0;i<400;i++)

{

arr1[i]=i;

}

fp=fopen("aaa.txt","w");

   for(i=0;i<399;i++)

{

for(j=0;j<=399;j++)

{

if(j==i)

fprintf(fp,"%f%c",b,' ');

else if(j==i+1 && i!=398)

   fprintf(fp,"%f%c",c,' ');

else if(j==i-1)

fprintf(fp,"%f%c",c,' ');

else if(j==399)

{  

fprintf(fp,"%f%c",arr1[i],' ');

}

else

fprintf(fp,"%f%c",0.0,' ');

}

}

fclose(fp);

cout<<arr1[9]<<endl;

return 0;

}


原网站

版权声明
本文为[51CTO]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/188/202207072135077639.html