### program not doing what it should

Hei! So i found my problem with endless printing in my program, but the result is still not right. It should print out 1729 (12^3 + 1^3 = 9^3 + 10^3), but it doesn't.

 ``12345678910111213141516171819202122232425262728293031`` ``````#include using namespace std; int maks(int num1, int num2); int main() { int atgr,m,n,sk=13; for (int k=1; k<=sk; k++){ for (int l=1; l<=sk; l++){ for (int i=1; i<=sk; i++){ for (int j=1; j<=sk; j++){ m= k*k*k + l*l*l; n= j*j*j + i*i*i; } } } } atgr=maks(m,n); cout<
Last edited on
 It should print out 1729 (12 + 1 = 9 + 10)
What? :s

m in the end is going to be equal to (I think, nested loops are confusing):
139 * (13!3 + (13 * 13!3))
It doesn't but the answer is not good.

Anyway, whatever the answer, it's going to be absolutely huge and overflow the int. What are you trying to do here? None of your code or description really makes any sense so far.
Last edited on
m is the 1729 where 1729=12^3+1^3 and 1729=9^3+10^3
oh you're doing cubes in the for loop and I guessed you're trying to solve the next one or something? You're being for some reason extremely sketchy on details... I took it the question is something like find 4 distinct positive integers such that a3 * b3 = c3 * d3?

You can do this with for loops but consider what you would do in real life. You would:

-Multiply all the numbers.
-Check if each side of the equation is equal.
-Check the numbers are distinct

Your program is failing to do the latter two steps after multiplying out the numbers.
Topic archived. No new replies allowed.