Write a program that given a pair of assignments f(x₁) = y₁ and f(x₂) = y₂, calculates the function f, given by f(x) = ax + b.
Example 1. If f(0) = 2 and f(2) = 3 then f(x) = x/2 + 2.
Example 2. If f(1) = 6 and f(4) = 12 then f(x) = 2x + 4.
The input contains a single line with 4 numbers x₁, y₁, x₂ and y₂
where 0 ≤ x₁, y₁, x₂, y₂ ≤ 100
The output should contain a single line with a function description to the
standard output in the form f(x) = A.A*x + B.B
where A.A
and B.B
are the coefficients rounded to one decimal place.
Inputs are given so that it is always possible to produce such function.
0 2 2 3
f(x) = 0.5*x + 2.0
1 6 4 12
f(x) = 2.0*x + 4.0
try first: pi
try next: function
Copyright © 2020-2022 Rudy Matela
This text is available under the CC BY-SA 4.0 license.
Originally available on cscx.org/function1