logo - 刷刷题
下载APP
【简答题】

下列给定程序中,函数 fun 的功能是:将自然数 1 ~ 10 及其平方根写到名为 myfile3.txt 的文本文件中,然后再顺序读出显示在屏幕上。 请在程序下画线处填入正确的内容并把下画线删除,使程序得出正确的结果。 #include #include int fun(char *fname ) { FILE *fp; int i,n; float x; if((fp=fopen(fname, "w"))==NULL) return 0; for(i=1;i<=10;i++) /**********found**********/ fprintf( 1 ,"%d %f\n",i,sqrt((double)i)); printf("\nSucceed! ! \n"); /**********found**********/ 2 ; printf("\nThe data in file :\n"); /**********found**********/ if((fp=fopen( 3 ,"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); }

举报
参考答案:
参考解析:
.
刷刷题刷刷变学霸