3. Write a program that asks the user to enter a value for x and then displays the value of the following polynomial 2x^5+3x^4-x^3-2x^2+7x-6.
#include <iostream>
using namespace std;
double f(double x) {
return ((((2.0*x + 3.0)*x - 1.0)*x - 2.0)*x + 7.0)*x - 6.0;
}
int main() {
double x, y;
cout << "Enter a value x: ";
cin >> x;
y = f(x);
cout << "2x^5+3x^4-x^3-2x^2+7x-6 = " << y << endl;
return 0;
}
Comments
Leave a comment