Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

C++ Program to Find Area of a Triangle

To calculate the area of a Triangle we need to have the lengths of all three sides, using "Heron's Formula" that has been known for nearly 2000 years. The following simple program inputs three sides of a triangle from the user and finds out triangle area by Heron's Formula:


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

Program Source Code


#include

#include

main()

 {

   float s, a, b, c, area;

   std :: cout
   std :: cin>>a;

   std :: cout
   std :: cin>>b;

   std :: cout
   std :: cin>>c;

          s = (a+b+c) / 2.0;

   area = sqrt (s*(s-a)*(s-b)*(s-c));

   std::  cout   std :: cout   return 0;

 }


Output of Program

Enter first side of triangle: 30
Enter second side of triangle: 40
Enter third side of triangle: 60

The sides of triangle = 30, 40, 60
Area of triangle = 533.268



This post first appeared on Programming Explain, please read the originial post: here

Share the post

C++ Program to Find Area of a Triangle

×

Subscribe to Programming Explain

Get updates delivered right to your inbox!

Thank you for your subscription

×