I wrote this recursive method but the problem is i need to do the same with a loop. First one is recursive, and the second one is loop but it`s not good. Any advice how to fix the loop method?
double SR(int n)
{
if (n > 1)
return Math.Sqrt(2 + SR(n - 1));
else
return Math.Sqrt(2);
}//recursion
double SR2(double n)
{
if(n > 1)
{
do
{
n = Math.Sqrt(2+Math.Sqrt(n - 1));
}
while(n <= 1);
}
else
{
n = Math.Sqrt(2);
}
return n; //loop
}