Projecteuler.net – Problem 10 – C solution

http://projecteuler.net/problem=10

The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.

Find the sum of all the primes below two million.

This one actually threw me for a loop. Not the problem, but rather the code I wrote seemed to be doing something other than what I wrote. What I have below works on my 64 bit OS at home. It does something strange when I compile on my 32 bit Windows XP work machine. I couldn’t get printf() to display my long long int properly. It kept treating it as though there was only 4 bytes when there was actually 8 bytes.

edit: I did a little digging and found a solution. In inttypes.h I found that I can use %I64i to more specifically tell printf() what I want it to display.

– Josh

This entry was posted in C, Project Euler. Bookmark the permalink.

Leave a Reply