1
I have an interesting problem in my code, the program reads three numbers and says whether it’s a rectangle triangle or not, but the problem is that depending on the sequence I type in the numbers, the program of the error, because the highest value entered must be that of the hypotenuse and whatever the other two catects, if I type 3, 4, 5, the value of 5 must be stored in the variable hypotenuse, but how do I do it, 5, 4, 3 of the right but the opposite not...
#include <stdio.h> //Inclusao da bibilioteca principal
#include <math.h> //Inclusao da biblioteca para uso da funcao "pow" e "sqrt"
int main (void) //Declaracao do corpo principal do programa
{
int hip, cat1, cat2; //Declaracao de variaveis hipoteusa, cateto 1 e cateto 2
scanf("%d", &hip); //Insercao pdo valor da hipotenusa
scanf("%d", &cat1); //Insercao do valor do cateto 1
scanf("%d", &cat2); //Insercao do valor do cateto 2
if (hip == sqrt(pow(cat1,2) + pow(cat2,2))) //Condicao para caso o valor da hipotenusa seja igual a raiz quadrada da soma dos quadrados dos catetos
{
printf("SIM"); //Caso a condicao acima seja verdade, imprimi na tela a palavra SIM
} else {
printf("NAO"); //Caso a condicao acima nao for satisfeita, imprimi na tela a palavra NAO
}
return 0;
}
Hypotenuse is always the largest side of the triangle. You can read side1, side2, side3, in any order. Then you do a function to find out which side is bigger. And only then do you apply your formula.
– GabrielOshiro