I'm trying to solve Project Euler #9, which is http://projecteuler.net/index.php?section=problems&id=9.
I've looked through this code, and the logic seems right…but I'm not getting any output at all, not even the printfs in the loop. I'm (obviously) a C newbie, trying to learn from higher level languages…could you tell me what's going wrong?
#include <stdio.h>
int main(){
unsigned int a=0, b=0, c=0;
short int pass=0;
while(!pass){
//printf("a = %4d\n", a);
a++;
b=a;
while(!pass){
b++;
c=1000-a-b;
if(b>=c) break;
if(a*a+b*b==c*c) pass = 1;
}
}
printf("a=%d, b=%d, c=%d, a*b*c=%d, a+b+c=%d\n", a, b, c, a*b*c,a+b+c);
return 1;
}
Thanks so much.
EDIT: Okay, I've fixed the floating point problem as shown above, but now a never goes above two for some reason, making it loop infinitely.
EDIT: I fixed some bugs, but still, it returns a=33, b=483, c=484, a*b*c=7714476, a+b+c=1000
, which isn't quite right. :(
Wow, I was overcomplicating it. It works now. Thanks everyone.