/* ========================================= Filename: collatz_sequence.c Filedate: February 25, 2007 Input a positive integer n. If it's even, divide by 2. If it's odd, multiply by 3 and add 1. Repeat until you get a 1. Note: It was conjectured by L. Collatz in 1937 that the sequence always halts, i.e., you eventually reach 1. As of 2006, the conjecture remains unresolved. Thwaites has offered a prize of 1000 English pounds for a solution. ========================================= */ #include #include int main() { int i; int current_value; int no_terms = 1; printf("Input a positive integer:\n"); scanf("%d", ¤t_value); do { printf("Current value is: %d\n",current_value); if (current_value%2 == 0) { current_value = current_value/2; } else { current_value = 3*current_value + 1; } no_terms++; } while(current_value != 1); printf("Reached the value 1 after %d steps.\n", no_terms); return(0); }