Is there some restriction from using the obvious three nested loops for this problem?
Not a particularly elegant solution, but it finds the answer in less than one second.
Code:
#include <stdio.h>
#define MAX 500
int main()
{
unsigned long int a,b,c,asqr,bsqr,csqr;
for(a=1;a<MAX;a++) {
for(b=1;b<MAX;b++) {
for(c=1;c<MAX;c++) {
if(a + b + c == 1000) {
asqr=a*a;
bsqr=b*b;
csqr=c*c;
if(asqr + bsqr == csqr) {
printf("\nasqr=%2lu bsqr=%2lu csqr=%2lu\n", asqr, bsqr, csqr);
printf("\nAnswer is: a=%lu b=%lu c=%lu", a,b,c);
printf("\n\n\t\t\t press enter when ready");
(void) getchar();
return 0;
}
}
}
}
}
printf("\n\n\t\t\t press enter when ready");
(void) getchar();
return 0;
}