Heron’s Formula for the area of a triangle(Hero’s Formula) A method for calculating the area of a triangle when you know the lengths of all three sides. Let a,b,c be the lengths of the sides of a triangle.
Heron’s formula states that the area of a triangle whose sides have lengths a, b, and c is
where s is the semiperimeter of the triangle; that is,
C Code
#include <stdio.h>
#include <conio.h>
#include <math.h>
void main()
{
float a, b, c, s, area;
printf("Enter Value For a: ");
scanf("%f", &a);
printf("Enter Value For b: ");
scanf("%f", &b);
printf("Enter Value For c: ");
scanf("%f", &c);
s = (a+b+c)/2;
area = sqrt(s*(s-a)*(s-b)*(s-c));
printf("Area of Triangle: %.3f", area);
getch();
}
C++ Code
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
float a, b, c, s, area;
cout << "Enter Value For a: ";
cin >> a;
cout << "Enter Value For b: ";
cin >> b;
cout << "Enter Value For c: ";
cin >> c;
s = (a+b+c)/2;
area = sqrt(s*(s-a)*(s-b)*(s-c));
cout << "Area of Triangle: " << area << endl;
return 0;
}
Output:
Other Related Search Terms
- C Program to Find Area of any triangle having values of 3 sides
- C++ program to find Area of any triangle having values of 3 sides
- C and C++ find area of any triangle using heron’s formula


![[C/C++] Program to Find The Area of Any Triangle](https://fsconline.info/wp-content/uploads/2015/09/c-cpp-programming.jpg)