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

(Geometry: area of a triangle) 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
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;
}
copy


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]


Need of Programmer

Need of Programmer

Comments

Popular posts from this blog

Write a program that reads a number in feet, converts it to meters, and displays the result. One foot is 0.305 meter.

Body Mass Index (BMI) is a measure of health based on height and weight. You can calculate your BMI by taking your weight in kilograms and dividing it by the square of your height in meters

Write a program that prompts the user to enter the coordinates of two points (x1, y1) and (x2, y2), and displays the slope of the line that connects the two points. The formula of the slope is (y2 - y1)/(x2 - x1).