Last active
May 3, 2022 10:51
-
-
Save arthurpbarros/a1063dd35be710324e97aa0b07077f67 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
/* | |
Descrição: Verifica se as dimensões do triângulo são positivas ou negativas | |
Parâmetros: | |
- a,b,c: lados do triângulo | |
Retorno: 0 -> Lados inválidos, 1 -> Lados válidos | |
*/ | |
int verifica_lados(int a,int b,int c){ | |
return (a <= 0 || b <= 0 || c <= 0)? 0 : 1; | |
} | |
/* | |
Descrição: Verifica se o triângulo é válido | |
Parâmetros: | |
- a,b,c: lados do triângulo | |
Retorno: 1 se o triângulo é válido, 0 se não é válido | |
*/ | |
int e_triangulo(int a, int b,int c){ | |
return (abs(b-c) < a && a < b+c && abs(a-c) < b && b < (a+c) && abs(a-b) < c && c < (a+b)); | |
} | |
/* | |
Descrição: Classifica um triângulo quanto aos lados | |
Parâmetros: | |
- a,b,c: lados do triângulo | |
Retorno: nenhum | |
*/ | |
void classificaTriangulo(int a, int b, int c){ | |
if (!verifica_lados(a,b,c)){ | |
printf("Lados inválidos. Existe ao menos um lado com dimensão negativa ou nula\n"); | |
}else if (!e_triangulo(a,b,c)){ | |
printf("Não é um triângulo verdadeiro, pois não satisfaz a condição de existência de um triângulo\n"); | |
}else{ | |
if (a == b && b == c && a == c){ | |
printf ("Triângulo equilátero\n"); | |
}else if(a != b && b != c && a != c){ | |
printf ("Triângulo escaleno\n"); | |
}else{ | |
printf ("Triângulo isósceles\n"); | |
} | |
} | |
} | |
int main(){ | |
int a,b,c; | |
printf("Digite os lados do triângulo: "); | |
scanf("%d %d %d", &a,&b,&c); | |
classificaTriangulo(a,b,c); | |
return 0; //insignificante | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment