Yesterday I was too tired to post correct and specific question. So there it is:
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);
}
Unfortunately program does not work as I want it to work. It should export the data to the file “data.txt”, but the file still looks like this:
# n Vka
0.00 0.00
Morover the program finishes operation just after creating this file, while I want it to finish its operation on printing Vk in the terminal.
fprintfThere’s no reason in this program to mess with
stdoutat all.