I wrote this, but when running it, the console just sits at “Running…” and won’t really do anything, at least that I can see. I am kind of at a loss here as I can’t think of anything else to do.
#include <iostream>
#include <cmath>
#include <cstdlib>
int main(void) {
int count = 0;
do {
int a = 1;
int b = 2;
int c = 3;
int total;
for (a=1;a<b;a++) {
for (b=2;b<c;b++) {
for (c=3;c<=1000;c++) {
total = a+b+c;
if (total == 1000 && a*a + b*b == c*c) {
std::cout << a << ", " << b << ", " << c;
}
}
}
}
count++;
} while(count < 1000);
return 0;
std::cin.get();
}
You might not see any output because your terminal is line-buffered and you never write a line break or flush the stream. To fix this you could add
std::endlto your output line:This way you should see all triples as soon as they are found, but the program will still take a long time to complete. It might even take a long time till any results are found. You could speed the program up by avoiding some of the nested loops.