Question

Write a program that prompts the user to enter three points (x1, y1), (x2, y2), (x3,...

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 distance of two points (x1, y1) and (x2, y2) is

d = Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));

or

d = Math.pow((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1), 0.5);

The formula for computing the area of a triangle is

s = (side1 + side2 + side3) / 2.0;

area = Math.sqrt(s * (s - side1) * (s - side2) * (s - side3));

or

area = Math.pow(s * (s - side1) * (s - side2) * (s - side3), 0.5);

Here is a sample run:

Enter three points for a triangle: 1.5 -3.4 4.6 5.0 9.5 -3.4

The area of the triangle is 33.60.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Since you have not provided the language of your preference, I am providing the code in Java.

import java.util.Scanner;

public class tester {

   public static double getDistance(double x1, double y1, double x2, double y2) {

       return Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));

   }

  

  

   public static void main(String[] args) {

       double x1, y1, x2, y2, x3, y3;

       Scanner sc = new Scanner(System.in);

       System.out.print("Enter three points for a triangle: ");

       x1 = sc.nextDouble();

       y1 = sc.nextDouble();

      

       x2 = sc.nextDouble();

       y2 = sc.nextDouble();

      

       x3 = sc.nextDouble();

       y3 = sc.nextDouble();

      

       double side1 = getDistance(x1, y1, x2, y2);

       double side2 = getDistance(x2, y2, x3, y3);

       double side3 = getDistance(x3, y3, x1, y1);

      

       double s = (side1 + side2 + side3) / 2.0;

       double area = Math.sqrt(s * (s - side1) * (s - side2) * (s - side3));

      

       System.out.format("The area of the triangle is : %.2f", area);

      

      

   }

}

Add a comment
Know the answer?
Add Answer to:
Write a program that prompts the user to enter three points (x1, y1), (x2, y2), (x3,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Must be in Python 3.6 (please have a screen shot on the code) ex 2.14 :...

    Must be in Python 3.6 (please have a screen shot on the code) ex 2.14 : # Enter three points for a triangle x1, y1, x2, y2, x3, y3 = eval(input("Enter three points for a triangle: ")) # Compute the length of the three sides side1 = ((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)) ** 0.5 side2 = ((x1 - x3) * (x1 - x3) + (y1 - y3) * (y1 -...

  • x1 X2 X3 Atnangle has vertices (x1y1)(X2 y2) and X3 Уз) The area of the triangle...

    x1 X2 X3 Atnangle has vertices (x1y1)(X2 y2) and X3 Уз) The area of the triangle IS given by the absolute value of D where D: y1 y2 y3 Use this formula to find the area of a triangle with vertices (6,8), (8,2), and (9,6) The area is square unit(s) Enter your answer in the answer box O Type here to search

  • Welcome to the Triangles program Enter length 1: 3 Enter length 2: 5 Enter length 3:...

    Welcome to the Triangles program Enter length 1: 3 Enter length 2: 5 Enter length 3: 5 Enter the base: 5 Enter the height: 8 --------------------- The triangle is Isosceles since it has two equal length sides. Isosceles triangle also has two equal angles The area is: 20 The permimeter is: 13 Continue? (y/n): y Enter length 1: 10 Enter length 2: 10 Enter length 3: 10 Enter the base: 10 Enter the height: 7 --------------------- The triangle is Equilateral...

  • The distance, d, between two points, (x1,y1)(x1,y1) and (x2,y2)(x2,y2), can be found using the formula d=√(x2−x1)^2+(y2−y1)^2....

    The distance, d, between two points, (x1,y1)(x1,y1) and (x2,y2)(x2,y2), can be found using the formula d=√(x2−x1)^2+(y2−y1)^2. How can you rearrange the given formula to correctly find y2?

  • Write a program that accepts (x1, y1) and (x2, y2) to specify line 1, (x3, y3)...

    Write a program that accepts (x1, y1) and (x2, y2) to specify line 1, (x3, y3) and (x4, y4) to specify line 2, computes and output the intersection of the two lines and the angle between them.

  • Create a UML diagram with 3 lines per class/interface including all constructors. public class Point {...

    Create a UML diagram with 3 lines per class/interface including all constructors. public class Point { public double X, Y; public Point() { this(0, 0); } public Point(double newX, double newY) { X = newX; Y = newY; } public static double distance(Point A, Point B) { return Math.sqrt(Math.pow(A.X-B.X, 2) + Math.pow(A.Y-B.Y, 2)); } } public interface Polygon { public int getNumberOfSides();    public double getPerimeter();    public double getArea();    } public abstract class Simple_polygon implements Polygon{ public Point...

  • 3) Let (x, y), (X2, y2), and (X3. Y3) be three points in R2 with X1...

    3) Let (x, y), (X2, y2), and (X3. Y3) be three points in R2 with X1 < x2 < X3. Suppose that y = ax + by + c is a parabola passing through the three points (x1, yı), (x2, y), and (x3, Y3). We have that a, b, and c must satisfy i = ax + bx + C V2 = ax + bx2 + c y3 = ax} + bx3 + c Let D = x X2 1....

  • 1(a)    Write a python program using a function name slope(x1, y1, x2, y2) that returns...

    1(a)    Write a python program using a function name slope(x1, y1, x2, y2) that returns the slope of the line through the points (x1, y1) and (x2, y2). 1(b) For problem 1(a), write a python program using a function name Euclidean_dist(x1, y1, x2, y2) which will calculate and return the Euclidean distance between the points (x1, y1) and (x2, y2).

  • matlab 3. Filename: area2d.m The area of a triangle whose three vertices are points (x1, yı),...

    matlab 3. Filename: area2d.m The area of a triangle whose three vertices are points (x1, yı), (X2, y2), and (x3, y3) can be found using the absolute value of the following equation: A = 3 [x: (– yz) – x2\1 – yz) + x3V1 – Yz)] Write a MATLAB function area2d that calculates the area of a triangle using the following syntax: A = area2d (x,y) where x and y are vectors such that x = [X1, X2, X3] and...

  • Set A contains three numbers x1, x2 and x3. Set B contains four numbers y1, y2,...

    Set A contains three numbers x1, x2 and x3. Set B contains four numbers y1, y2, y3 and y4. These two sets have the following characteristics: Set Mean Standard deviation A 10 2 B 45 5 Set X consists of the following eight numbers: u1 =70, u2 =7x1, u3 =7x2, u4 =7x3, u5 =2y1, u6 =2y2, u7 =2y3, u8 =2y4. Find the mean and standard deviation of the numbers in set X.

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT