You must loop using @jubjub's code, until the series hits 0, counting how many times through the loop:
#include <iostream>
#include <cmath> // pour exp()
using namespace std;
int main()
{
for (int n=0; n<9; ++n)
{
int count = 0, next = n;
while (next != 0 && count >= 0)
{
if (next % 3 == 0)
next += 4;
else if (next % 4 == 0)
next /= 2;
else
next --;
count ++;
}
if (count < 0)
cout << "n=" << n << ": could not converge to 0" << endl;
else
cout << "n=" << n << ": required " << count << endl;
}
return 0;
}
I don't know for this specific series if there is a proof that it will always converge to zero in fewer than some number of steps that depends on n. But I have included a guard in case "count" wraps around to negative numbers.