i have this code
i worked this out and then checked the answer i was wrong and found a couple of mistakes but now when i run it its an infinite loop. (i put the answer in and got up to a chain of over 3000) but cant for the life of me see what the issue is i think some of it is that x gets way too big before it starts getting to a sensible numberCode:#include <stdio.h> #include <stdlib.h> #define LIMIT 1000000 int even_num(long long unsigned int x); int odd_num(long long unsigned int x); int main() { int i, tmp_chain, chain, result; long long unsigned int x; for (i = 1; i < LIMIT; i++) { tmp_chain = 0; x = i; while (x > 1) { if (x % 2 == 0) // i is even { x = even_num(x); } else { x = odd_num(x); } tmp_chain++; } if (tmp_chain > chain) { result = i; chain = tmp_chain; } } printf("result is %d and chain is %d\n", result, chain); return 0; } int even_num(long long unsigned int x) { return x/2; } int odd_num(long long unsigned int x) { x *= 3; x += 1; return x; }
coop