I'm testing to see if the sides make up a right triangle (a^2 + b^2 = c^2), but how do I make it so that, no matter the order put in, "c" will always be the largest of the three?
raptr_dflo 48
I'm testing to see if the sides make up a right triangle (a^2 + b^2 = c^2), but how do I make it so that, no matter the order put in, "c" will always be the largest of the three?
If c is not the largest, simply swap it with another element. The following should be sufficient:
// input values a, b, c here
if (a > c) {
// a is bigger, so use it for c
swap(a, c);
}
if (b > c) {
// either way (note: not "else if"), if b is now bigger, use it for c
swap(b, c);
}
// continue with test for right-triangle
I'll leave it to you to write a function called swap() which swaps it's two arguments (in such a way that the values get returned to the main program!), or just replace the function calls with the code to perform the swap.