填空题
给定程序中,函数fun的功能是:将自然数1~10以及它们的平方根写到名为myfile3.txt的文本文件中,然后再顺序读出显示在屏幕上。
请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。
不得增行或删行,也不得更改程序的结构!
给定源程序:
#include<math.h>
#include<stdio.h>
intfun(char*fname)
{FILE*fp;int i,n;float x;
if((fp=fopen fname,”w'))==NULL)return ();
for(i=1;i<=10;i++)
/**********found**********/
fprintf(______,'%d %f\n',i,sqrt((double)i));
printf('\nSucceed!!\n');
/**********found**********/
______;
printf('\nThe data in file:\n');
/**********found**********/
if((fp=fopen(______,'r'))==NULL)
return 0:
fscanf(fp,'%d%f',&n,&x);
while(!feof(fp))
{printf('%d%f\n',n,x);
fscanf(fp,'%d%f',&n,&x);}
fclose(fp);
return 1;
}
main()
{char fname[]='myfile3.txt';
fun(fname);
}