Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Write a program that reads 3 points and calculate the area formed by these three points. If the triangle cannot be formed, indicate that the triangle cannot be formed.
- A possible run may look like:
- Enter three points: 1 1 1 4 5 1
- The area formed by (1.00, 1.00), (1.00, 4.00), and (5.00, 1.00) is 6.00.
- Hint:
- 1. Math.sqrt
- 2. The distance between two points (x1, y1) and (x2, y2) is sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)).
- 3. Suppose a triangle with 3 sides: a, b, c. s = (a + b + c)/2. The area of the triangle is
- sqrt(s * (s - a) * (s - b) * (s - c)).
- Question 2:
- Read two points and calculate the line equation formed by these two points in the form of ax + by = c. A possible run may look like:
- Enter two points: -4 6 8 -3
- The line is 3.000x + 4.000y = 12.000
- Enter two points: 1 1 1 1
- The line cannot be formed.
- Hint: The line equation passing two points (a, b) and (c, d) is
- (b - d)x + (c - a)y = a(b - d) + b(c - a).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement