To find the area of any triangle in which values of three sides are given we can use Heron's formula
which is equal to:
C++ Program to find the area of any triangle using Heron's Formula
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
float first,second,third;
float s,area;
cout<<"Enter size of each sides of triangle"<<endl;
cout<<"Enter size for First Side =";
cin>>first;
cout<<"Enter size for Second Side =";
cin>>second;
cout<<"Enter size for Third Side =";
cin>>third;
s = (first+second+third)/2;
area = sqrt(s*(s-first)*(s-second)*(s-third));
cout<<"Area of Triangle= "<<area<<endl;
return 0;
}
Sample Output:
Image view of Code:
which is equal to:
Note: To apply Heron's formula there should be values of all three sides of a triangle.
C++ Program to find the area of any triangle using Heron's Formula
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
float first,second,third;
float s,area;
cout<<"Enter size of each sides of triangle"<<endl;
cout<<"Enter size for First Side =";
cin>>first;
cout<<"Enter size for Second Side =";
cin>>second;
cout<<"Enter size for Third Side =";
cin>>third;
s = (first+second+third)/2;
area = sqrt(s*(s-first)*(s-second)*(s-third));
cout<<"Area of Triangle= "<<area<<endl;
return 0;
}
Sample Output:
Image view of Code:
why use the float?
ReplyDeleteTo get the decimal value.. by using int we cannot get the value if result contains decimal part.
DeleteTo get the decimal value or we can say to find the floating point no because area can be flaot no also..
DeleteThis comment has been removed by the author.
ReplyDeleteHow to find the area if three points (x1,y1) (x2,y2) and (x3,y3) is given?
ReplyDeleteNice blog.. Thanks for sharing informative blog.. its very useful to me..
ReplyDeletec programming training
Its good. Keep it up!
ReplyDeleteProgram to find out the area of triangle and if any side is 0 then display the message there is no triangle
DeleteTo find out the area of triangle and if any side is 0 then display the message "there is no triangle
ReplyDeleteIf any side zero to.print " there is no triangle using if statement
ReplyDelete