C Program to find area of scalene triangle

For a better understanding, we always recommend you to learn the basic topics of C programming listed below:

What is the scalene triangle?

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

In this C program, we need to find the triangle area, given the sides and angle between them. Normally we used to calculate the area of a scalene triangle using the equation, area = 1/2 X base X height. Here we are using another well-known formula and applying it in this program. 

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

where s1,s2 are adjacent sides of the triangle and angle is the angle between those sides. To covert the angle in degrees to radian use the formula (M_PI / 180) X angle, M_PI is a Constant defined in math.h header file that contains the value 3.14. And use the radian value of the angle in sin() function to calculate the area.

How to implement area calculation of triangle in C

In this c program, we first accept the triangle sides; also, we ask the user to enter the angle between them, which we need to calculate the area. After getting the triangle's desired angle and sides, we apply our formula to calculate the triangle area. Here we are using the sine(angle) to find the area of the triangle. After calculation of the area, display the output of the C program using the float data type.


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

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

STEP 3: Accept the side1 of a triangle into the variable s1.

STEP 4: Accept the side2 of a triangle into the variable s2.

STEP 5: Accept the angle of the triangle into the variable angle.

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

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

C Source Code


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);


Enter Side1 : 3
Enter Side2 : 4

Enter included angle : 30
Area of Scalene Triangle : 3.000000