Skip to content

Instantly share code, notes, and snippets.

@oykelrae
Last active December 4, 2019 21:50
Show Gist options
  • Save oykelrae/37ec5c3c4ba219507da9b15fe33207e4 to your computer and use it in GitHub Desktop.
Save oykelrae/37ec5c3c4ba219507da9b15fe33207e4 to your computer and use it in GitHub Desktop.
<math.h> The area of a triangle given 3 sides
#include <stdio.h>
#include <math.h>
int main() {
double s1, s2, s3, p, area;
printf("Enter the lengths of 3 sides of a triangle: ");
scanf("%lf %lf %lf", &s1, &s2, &s3);
p = (s1 + s2 + s3) / 2;
area = sqrt(p*(p-s1)*(p-s2)*(p-s3));
printf("The area of the triangle is %.2lf\n", area);
return (0);
}
Enter the lengths of 3 sides of a triangle: 8 11 5
The area of the triangle is 18.33
Program ended with exit code: 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment