Skip to content

Instantly share code, notes, and snippets.

@tieubinhco
Created March 11, 2018 18:40
Show Gist options
  • Save tieubinhco/18b16ca825208af766105da61a838a46 to your computer and use it in GitHub Desktop.
Save tieubinhco/18b16ca825208af766105da61a838a46 to your computer and use it in GitHub Desktop.
Calculate the area of a triangle in C
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
void main()
{
double a,b,c;
printf("Enter triangle lengths a, b, c: \n");
scanf("%lf %lf %lf", &a,&b,&c);
if (a+b<=c || a+c<=b || b+c<=a || a<=0 || b<=0 || c<=0)
printf("\nInvalid triangle lengths!!!\n\n");
else { double d,s;
d=(a+b+c)/2;
s=sqrt((d-a)*(d-b)*(d-c)*d);
printf("The area of this triangle is %f \n\n" ,s);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment