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.
#include <iostream>
usingnamespace 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<<atgr<<endl;
}
int maks(int num1, int num2){
int m;
if (num1==num2) m=num1;
return m;
}
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.
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 a^{3} * b^{3} = c^{3} * d^{3}?
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.