Created
March 11, 2018 18:40
-
-
Save tieubinhco/18b16ca825208af766105da61a838a46 to your computer and use it in GitHub Desktop.
Calculate the area of a triangle in C
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> | |
#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