Assignments » Library Function » Set1 » Solution 2

Write a program to compute area of triangle. Sides are input by user.
Area = sqrt(s*(s-a)*(s-b)*(s-c))
where s=(a+b+c)/2

#include<iostream.h>
#include<conio.h>
#include<math.h>

int main()
{
	float a,b,c,s,Area;
	cout<<"Enter three sides of triangle : ";
	cin>>a>>b>>c;
	s=(a+b+c)/2;
	Area=sqrt(s*(s-a)*(s-b)*(s-c));
	cout<<"Area of triangle is : "<<Area;
	getch();
	return 0;
}

#include<iostream>
#include<cmath>
using namespace std;

int main()
{
	float a,b,c,s,Area;
	cout<<"Enter three sides of triangle : ";
	cin>>a>>b>>c;
	s=(a+b+c)/2;
	Area=sqrt(s*(s-a)*(s-b)*(s-c));
	cout<<"Area of triangle is : "<<Area;
	
	return 0;
}

Enter three sides of triangle : 5.6 8.1 10.3
Area of triangle is : 22.5651

 

«back