Question
Write a program that reads in the coordinates of the three vertices of a triangle and prints out the area of the triangle. The input
Write a program that reads in the coordinates of the three vertices of a triangle and prints out the area of the triangle. The input will come as pairs of numbers separated by a space and may include decimal values.
To calculate the area of the triangle, use Heron's formula:
A=sqrt s(s-a)(s-b)(s-c)
Where a, b, and c are the lengths of the sides and s is the semi perimeter: (a + b + c)/2.
To calculate the length of each side, you will need to use the distance formula:
Length = sqrt (x sub 2 - x sub 1)^2 + (y sub2 - y sub1)^2
Sample run:
The given input represents a point at 1, 1 another at 4, 1 and a third at 1, 5.
Enter x y for point 1: 1 1 Enter x y for point 2: 4 1 Enter x y for point 3: 1 5 The area of the triangle is 6
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started