Entry 3134
Exercício sobre triângulos do CSoC
Submitted by Alex Tercete
on Feb. 5, 2010 at 11 a.m.
Language: C. Code size: 1.2 KB.
#include <stdio.h> int triangulo_existe(float a, float b, float c); void tipo_triangulo(float a, float b, float c); void triangulo_retangulo(float a, float b, float c); int main() { float a, b, c; printf("Digite os lados de um triangulo, separados por virgulas.\n"); printf("-> Exemplo: 3.1,4.2,5.3\n"); scanf("%f%*c%f%*c%f", &a, &b, &c); if ( triangulo_existe(a, b, c) ) { printf("Os tres segmentos formam um triangulo\n"); tipo_triangulo(a, b, c); triangulo_retangulo(a, b, c); } else { printf("Os tres segmentos nao podem formar um triangulo\n"); } } int triangulo_existe(float a, float b, float c) { return (a < b + c) && (b < a + c) && (c < a + b); } void tipo_triangulo(float a, float b, float c) { const char* tipo; if (a == b && a == c) { tipo = "equilatero"; } else if (a != b && a != c && b != c) { tipo = "escaleno"; } else { tipo = "isosceles"; } printf("O triangulo eh %s\n", tipo); } void triangulo_retangulo(float a, float b, float c) { if (a*a == b*b + c*c || b*b == a*a + c*c || c*c == a*a + b*b) { printf("O triangulo eh retangulo\n"); } }
This snippet took 0.01 seconds to highlight.
Back to the Entry List or Home.