UVA ! first problem 3n + 1 (easy)

OK, this is my first problem solved on uva!

#include #include #include using namespace std ; int algo(int n){ int total = 0 ; while( n >= 1){ total++ ; if( n == 1) { return total ;} else if( n % 2 == 1) n = 3 * n + 1 ; else n = n / 2 ; } } void check_cycles(int i , int j, bool swapped){ int max_cycle_len = 0 ; int current_cycle_len = 0 ; for(int num = i ; num <= j ; num++){ current_cycle_len = algo(num) ; if(current_cycle_len > max_cycle_len) max_cycle_len = current_cycle_len ; } if(swapped) cout << j << " "<< i<< " " << max_cycle_len< j ){ swapped = true ; int temp = i ; i = j ; j = temp ; } check_cycles(i, j,swapped) ; } return 0 ; }