Write a program that prompts the user to enter three points (x1, y1), (x2, y2), (x3, y3) of a triangle and displays its area. The formula for computing the area of a triangle is
points (x1, y1), (x2, y2), (x3, y3) of a triangle and displays its area. The formula
for computing the area of a triangle is
s = (side1 + side2 + side3)/2;
area = 2√s(s - side1)(s - side2)(s - side3)
#Beginner
In gcc c++ compiler using namespace std;
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
float x1,y1,x2,y2,x3,y3;
cout<<"Enter three point of triangle:"<<endl;
cout<<"point1 x1 and y1 :";
cin>>x1>>y1;
cout<<"point2 x2 and y2 :";
cin>>x2>>y2;
cout<<"point3 x3 and y3 :";
cin>>x3>>y3;
float side1=sqrt(pow(x2-x1,2)+pow(y2-y1,2));
float side2=sqrt(pow(x3-x2,2)+pow(y3-y2,2));
float side3=sqrt(pow(x1-x3,2)+pow(y1-y3,2));
float s=(side1+side2+side3)/2;
float area=sqrt(s*(s-side1)*(s-side2)*(s-side3));
cout<<"The area of the triagle is :"<<area;
return 0;
}
Output
Enter three point of triangle:
point1 x1 and y1 :2 4
point2 x2 and y2 :2 0
point3 x3 and y3 :5 0
The area of the triagle is :6
[Program finished]
Comments
Post a Comment
Any doubt about programming or questions