Skip to content

Instantly share code, notes, and snippets.

@oykelrae
Last active December 4, 2019 21:50
Show Gist options
  • Save oykelrae/9f4033a5dda1aed1a3ca090f535a83cc to your computer and use it in GitHub Desktop.
Save oykelrae/9f4033a5dda1aed1a3ca090f535a83cc to your computer and use it in GitHub Desktop.
<math.h> The area of a triangle given 2 sides and the angle between them
#include <stdio.h>
#include <math.h>
int main() {
double s1, s2, angle, area;
printf("Enter the lengths of two sides of a triangle: ");
scanf("%lf %lf", &s1, &s2);
printf("Enter the angle between them (in degrees): ");
scanf("%lf", &angle);
area = (s1 * s2 * sin((3.141593 / 180) * angle)) / 2;
printf("The area of the triangle is %.2lf\n", area);
return (0);
}
Enter the lengths of two sides of a triangle: 7 5
Enter the angle between them (in degrees): 30
The area of the triangle is 8.75
Program ended with exit code: 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment