Skip to content

Instantly share code, notes, and snippets.

@jq2
Created February 13, 2018 22:42
Show Gist options
  • Save jq2/9a2246c8737421611f243219e68da5df to your computer and use it in GitHub Desktop.
Save jq2/9a2246c8737421611f243219e68da5df to your computer and use it in GitHub Desktop.
Fórmula de Heron
Teorema de herão... fiz certo ?
float AreaTriangulo(int a, int b, int c)
{
double s = (a+b+c)/2;
double x = ((s) * (s-a) * (s-b) * (s-c));
double area = sqrt(x);
return area;
}
#include <stdio.h>
int main() {
float a, b, c, s, area;
int i=0;
printf("Informe os dois lados do triângulo: ");
scanf("%f %f", &a, &b);
while (a <= 0 || b <= 0) {
printf("Os lados precisam ser positivos.\nInforme os dois lados do triângulo: ");
scanf("%f %f", &a, &b);
}
for (c=0.1; c<(a+b); c+=0.1) {
s = (a + b + c) / 2;
area = sqrt(s * (s-a) * (s-b) * (s-c)); /* Teorema de Heron */
printf("\n%d\tlados: (%.1f, %.1f, %.1f)\tárea: %f", ++i, a, b, c, area);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment