...

/

Discussion: More Math, but Fun This Time

Discussion: More Math, but Fun This Time

Execute the code to understand the output and gain insights into recursive approximation.

Run the code

Now, it's time to execute the code and observe the output.

Press + to interact
#include <stdio.h>
double phi(double p, int precision)
{
while(precision)
return( p + 1/phi(p, precision-1) );
return(p);
}
int main()
{
double gr;
gr = phi(1.0, 15);
printf("Phi is %f\n", gr);
return(0);
}

Understanding the output

The code outputs the following line:

Phi is 1.618034
Code output

This is the golden ratio, represented by Greek letter phi, ϕϕ.

Golden ratio

...