У меня возникли проблемы с преобразованием следующего кода из циклов в использование только рекурсии.
//longestHailstoneStartValue also cycles through each of the sequences from 1
//to 'n' and after it is determined what the largest length is, it finds which
//number corresponds with the longest length function.
//
//Sample input: '8'
//Sample output: '7'
//'7' is from the sequence starting with 7.
int longestHailstoneStartValue(int n)
{
int u=1, w=0, z=0;
while(n>=u)
{
if(w<lengthHailstone(u))
{
w=lengthHailstone(u);
z=u;
}
u++;
}
return z;
}
Я должен преобразовать это в рекурсию и в любом случае взять любые дополнительные переменные, которые не используются / с новыми значениями, хранящимися в них.