I ve to create a pi approximation based on Archimedes equation. I ve to do so with for mode and recursive mode. In for mode i ve create sth like the above:
double Pi_approximation(double r, double L){
int i;
double fin;
double y;
for(i=1; i<4; i++){
y =sqrt(2*((r*r) - r*(sqrt(4*((r*r) - (L))))));
L = y;
printf("%f \n", L);
}
return y;
}
My problem is in second loop of for. In the first y is calculated normally but in second loop when i print y and L, it prints me their pointer!! Any idea?
It’s hard to be sure what is happening, but I will take a guess anyway! Most likely the value you pass to one of the
sqrt()calls is negative. When this happens,y(and henceL) will beNaN. The output then will be compiler dependent. For example on my compiler the output is: