I'm just doing a simple excercise today and I wrote this fuction--ALG--And I'm getting the weirdest outputs. I have taken the liberty to insert a printf right before the return, and to my confusion it prints the right awnser however one that differs with my real output.

Code:

#include <stdio.h>

int alg( int n, int cnt ) {

if( n == 1 ) {

//dismay
printf("%d", cnt);
return cnt;

}

else if ( n%2 == 0 )
alg( n/2, ++cnt);

else
alg( (3*n)+1, ++cnt);

}

int main() {

printf(" %d ", alg(10, 1) );
return 0;

}

Btw, I use to have this real handy dandy visual debugger in my jgrasp/cygwin superhero combo plus but ever since I updated cygwin it went away. If anyone can point out that package to me it would be great. Thx.