Project Euler problem 7 in C