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 in the radius and length of a cylinder and computes the area and volume using the following formulas: area = radius * radius * π volume = area * length

Write a program that reads the subtotal and the gratuity rate, then computes the gratuity and total. For example, if the user enters 10 for subtotal and 15% for gratuity rate, the program displays $1.5 as gratuity and $11.5 as total.

Write a program that prompts the user to enter the min- utes (e.g., 1 billion), and displays the number of years and days for the minutes. For simplicity, assume a year has 365 days