C program to find area of triangle

C program to find area of triangle: c programming code to calculate area of a triangle using Heron's or Hero's formula. User will enter the lengths of sides of triangle. Remember for a triangle to exist the sum of any two sides of a triangle must be greater than third side.

C programming code

/* Assuming Triangle exists - valid input from user */
 
#include<stdio.h>
#include<math.h>
 
main()
{
   double a, b, c, s, area;
 
   printf("Enter the sides of triangle\n");
 
   scanf("%lf%lf%lf",&a,&b,&c);
 
   s = (a+b+c)/2;
 
   area = sqrt(s*(s-a)*(s-b)*(s-c));
 
   printf("Area of triangle = %.2lf\n", area);
 
   return 0;
}

C program to find area of triangle using function

#include<stdio.h>
#include<math.h>
 
double area_of_triangle(double, double, double);
 
main()
{
   double a, b, c, area;
 
   printf("Enter the sides of triangle\n");
 
   scanf("%lf%lf%lf",&a,&b,&c);
 
   area = area_of_triangle(a, b, c);
 
   printf("Area of triangle = %.2lf\n", area);
 
   return 0;
}
 
double area_of_triangle( double a, double b, double c )
{
   double s, area;
 
   s = (a+b+c)/2;
 
   area = sqrt(s*(s-a)*(s-b)*(s-c));
 
   return area;
}
randomness