Header Ads Widget

C++ program to calculate the area of the triangle using formula at= root s(s-a)(s-b)(s-c)

C++ program to calculate the area of the triangle using formula at= root s(s-a)(s-b)(s-c) 

Given sides of the triangle , write a program to calculate the area of the triangle . 

Sample input 

2 3 4

Sample output

Area of the triangle is: 2.90474

C++ program to calculate the area of the triangle using formula at= root s(s-a)(s-b)(s-c)

The objective of the code is to calculate the area of the triangle . For calculating area of the triangle we will use the formula .



 Code(C++):-

#include <bits/stdc++.h>
using namespace std;
int main()
{
float s,a,b,c,area;
cout<<"Enter sides of the triangle\n";
cin>>a>>b>>c;
s=(a+b+c)/2;
area=sqrt(s*(s-a)*(s-b)*(s-c));
cout<<"Area of the triangle is: "<<area;
return 0;
}

Output:-


Enter the sides of the triangle
2 3 4
Area of the triangle is : 2.904737




Recommended Post :-

HCL Coding Questions:-

Capgemini Coding Questions:-

Companies interview:-

Full C course:-    

Key points:-

Cracking the coding interview:-

 Array and string:-

Tree and graph:-

Hackerearth Problems:-

Hackerrank Problems:-

Data structure:-

 MCQs:-