C Program to find area of scalene triangle


March 4, 2022, Learn eTutorial
1580

What is the scalene triangle?

The scalene triangle is a triangle in which they have three unequal sides. The interior angles of the scalene triangle are always different since they have unequal sides. In this C program, we have to find the area of a scalene triangle.

To find the triangle area, we need the sides and the angle between them. here we are using well-known formula. 

'Area = (s1 * s2 * sin((M_PI / 180) * angle)) / 2'

where,

  • s1, s2 are adjacent sides
  • angle is the angle between those sides.

To convert the angle in degrees to radians use the formula (M_PI / 180) X angle.

  • M_PI is a Constant with a value of 3.14

then we use the angle value in sin() function to calculate the area.

How to implement area calculation of triangle in C

To implement this formula in C program, we first accept the triangle sides and angle from the user. After receiving the user inputs, we apply our formula to calculate the triangle area. Here we are using the sine(angle) to find the area. Finally, display the output.

ALGORITHM

STEP 1: Include the header files to use the built-in functions.

STEP 2: Declare the variable s1, s2, angle as integer, and area as a Float.

STEP 3: Accept the side1 into the variable s1.

STEP 4: Accept the side2 into the variable s2.

STEP 5: Accept the angle into the variable angle.

STEP 6: Calculate area=s1 * s2 * sin((M_PI / 180) * angle)) / 2

STEP 7: Display the area of the Scalene triangle as area and return.


To find the area of a scalene triangle, we use the below concepts of C programming, please refer to those for better understanding

C Source Code

                                          #include<stdio.h>
#include<math.h>

int main() {
  int s1, s2, angle;
  float area;
  printf("\nEnter Side1 : "); /* accepting the side of triangle */
  scanf("%d", & s1);
  printf("\nEnter Side2 : ");
  scanf("%d", & s2);
  printf("\nEnter included angle : "); /* accepting angle of triangle */
  scanf("%d", & angle );
  area = (s1 * s2 * sin((M_PI / 180) * angle)) / 2; /* calculating area using formula */
  printf("\nArea of Scalene Triangle : %f", area); /* printing the output */
  return (0);
}
                                      

OUTPUT

Enter Side1 : 3
Enter Side2 : 4

Enter included angle : 30
Area of Scalene Triangle : 3.000000