include iostream include cmath using namespace std double double retur

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
#include <cmath>
using namespace std;
double f(double x) {
return pow(x, 2);
}
double interpolate(double x, double x1, double x2) {
return f(x1) + (f(x2) - f(x1)) * (x - x1) / (x2 - x1);
}
int main() {
double x1, x2, x;
cout << "Enter x1:" << endl;
cin >> x1;
cout << "Enter x2:" << endl;
cin >> x2;
cout << "Enter x between x1 and x2:" << endl;
cin >> x;
cout << "f(x) = " << interpolate(x, x1, x2) << endl;
return 0;
}