Problema: 1045
Enunciado:
Leia 3 valores de ponto flutuante A, B e C e ordene-os em ordem decrescente, de modo que o lado A representa o maior dos 3 lados. A seguir, determine o tipo de triângulo que estes três lados formam, com base nos seguintes casos, sempre escrevendo uma mensagem adequada:
- se A ≥ B+C, apresente a mensagem: NAO FORMA TRIANGULO
- se A2 = B2 + C2, apresente a mensagem: TRIANGULO RETANGULO
- se A2 > B2 + C2, apresente a mensagem: TRIANGULO OBTUSANGULO
- se A2 < B2 + C2, apresente a mensagem: TRIANGULO ACUTANGULO
- se os três lados forem iguais, apresente a mensagem: TRIANGULO EQUILATERO
- se apenas dois dos lados forem iguais, apresente a mensagem: TRIANGULO ISOSCELES
Linguagem: C
Solução:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | #include <stdio.h> #include <math.h> int main (){ double a, b, c, aux; scanf("%lf %lf %lf", &a, &b, &c); if (a > b && a > c && c > b) { aux = b; b = c; c = aux; } if (b > a && b > c) { aux = a; a = b; b = aux; if (c > b) { aux = c; c = b; b = aux; } } if (c > a && c > b) { aux = a; a = c; c = aux; if (c > b) { aux = c; c = b; b = aux; } } if (a >= b + c) printf("NAO FORMA TRIANGULO\n"); else if (pow(a,2) == pow(b,2) + pow(c,2)) printf("TRIANGULO RETANGULO\n"); else if (pow(a,2) > pow(b,2) + pow(c,2)) printf("TRIANGULO OBTUSANGULO\n"); else printf("TRIANGULO ACUTANGULO\n"); if (a == b && b == c) printf("TRIANGULO EQUILATERO\n"); else if (a == b || a == c || b == c) printf("TRIANGULO ISOSCELES\n"); return 0; } |
Nenhum comentário:
Postar um comentário