Given C++ function definition
int mystery(int n)
{
int k = n;
int r = 0;
while(k > 1)
{
if(k % 2 == 0) k = k/2;
else k = 3*k + 1;
r = r + 1;
}
return r;
}
what does mystery(7) return?
Given C++ function definitions
void funny(int& x, int y)
{
x = y + 1;
y = 25;
}
int test()
{
int x = 105;
int y = 500;
funny(y,x);
return y*10 + x;
}
what does test() return?
Write a C++ function definition for function sumcube where sumcube(n) = 13 + 23 + 33 + ... + n3. Use a loop to do the work.
Write the same function sumcube, but this time do not use any kind of loop. Instead, use recursion.