Rose L.

asked • 28d

Programming 4-21

Let l be a line in the x-y plane. If l is a vertical line, its equation is x = a for some real number a.

Suppose l is not a vertical line and its slope is m. Then the equation of l is y = mx + b, where b is the y-intercept.

If l passes through the point (x₀, y₀), the equation of l can be written as y - y₀ = m(x - x₀).

If (x₁, y₁) and (x₂, y₂) are two points in the x-y plane and x₁ ≠ x₂, the slope of line passing through these points is m = (y₂ - y₁)/(x₂ - x₁).


Write a program that prompts the user for two points in the x-y plane. Input should be entered in the following order:

Input x₁

Input y₁

Input x₂

Input y₂

The program:

Outputs the equation of the line

Uses if statements to determine and output whether the line is vertical, horizontal, increasing, or decreasing.

If l is a non-vertical line, output its equation in the form y = mx + b.

Note: Output all numbers with a precision of two decimal places.

1 Expert Answer


Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.


Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.