昨天我太累了,无法发布正确和具体的问题。所以它是:
if (t==2){
printf ("abc\n");
printf ("abc = "); scanf ("%f",&r);
printf ("abc = "); scanf ("%d",&n);
printf ("abc = "); scanf ("%d",&k);
a=2*r;
b=2*r;
c=2*r;
for (i=0;i<=n;i++){
float x=(float)rand()/((float)RAND_MAX/a);
float y=(float)rand()/((float)RAND_MAX/b);
float z=(float)rand()/((float)RAND_MAX/c);
if ((x-(r))*(x-(r))+(y-(r))*(y-(r))+(z-(r))*(z-(r))<=(r*r))
m++;
if ( i % k ==0 && i > 0 ){
freopen ( "data.txt","w", stdout );
printf("%s %s %s \n","#","n","Vka");
Vka = ( 2*r*2*r*2*r )*m/i;
printf("% 6.2f % 6.2f \n",n,Vka);
fclose (stdout);
}
}
Vk=(2*r*2*r*2*r)*m/n;
printf ("abc =%d\n", m);
printf ("abc=%d\n", n);
printf("abc =%f", Vk);
}
不幸的是,程序不能像我希望的那样工作。它应该将数据导出到文件“data.txt”,但文件仍然如下所示:
# n Vka
0.00 0.00
Morover 程序在创建此文件后完成操作,而我希望它完成在终端中打印 Vk 的操作。