Find area of triangle - C Program

C program to find area of triangle.

Solution:

Formula:


formula

Where, s = (a+b+c)/2

In this program, we will accept three sides of the triangle from the user then find area using above formula. To find the square root use "sqrt function" which is included in math.h header file.

#include<stdio.h>
#include<math.h>
int main()
{
     int a,b,c;
     float s,tri_area;
     printf("Enter Sides of Triangle\n");
     printf("----------------------------\n");
     printf("Enter First Side  : ");
     scanf("%d",&a);
     printf("Enter Second Side : ");
     scanf("%d",&b);
     printf("Enter Third Side  : ");
     scanf("%d",&c);
     s =(a+b+c)/2.0;
     tri_area=sqrt(s*(s-a)*(s-b)*(s-c));
     printf("----------------------------\n");
     /* %.3f is used to print an area up to three decimal places.
     Otherwise, it will take default 6 decimal places*/
     printf("Area of Triangle = %.3f",tri_area);
     return 0;
}


Output:

area of triangle