#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main()
{
int i,j,r,c=0;
float x,y,z,eq,pi,S,V;
printf("-:VOLUME AND SURFACE OF SPHERE:-\n\n\n");
printf("ENTER THE VALUE OF THE RADIUS OF THE SPHERE: ");
scanf("%d",&r);
for (i=1;i<=10000;i++)
{
x=(rand()%(2*r+1)+(-1*r));
y=(rand()%(2*r+1)+(-1*r));
z=(rand()%(2*r+1)+(-1*r));
eq=pow(x,2)+pow(y,2)+pow(z,2);
if (abs(eq)<=pow(r,2))
{
c=c+1;
}
}
pi=6*c/float(i);
V=4*pi*pow(r,3)/float(3);
S=4*pi*pow(r,2);
printf("Pi IS %f\n\n\n\n",pi);
printf("VOLUME OF THE SPHERE IS %f\n\n\n\n ",V);
printf("SURFACE AREA OF THE SPHERE IS %f\n\n\n\n ",S);
}
Execution
For students : you can download and use Dev c++ compiler for executing this program.