-1
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
using namespace std;
int main()
{
vector<double> coefficients;
cout << "Enter the polynomial coefficients (increasing degree): ";
string line;
getline(cin,line);
istringstream input_string(line);
double coefficient;
while (input_string >>coefficient)
{
coefficients.push_back(coefficient);
}
double x;
cout <<"Enter the x value: ";
cin >> x;
double value = 0,power_x = 1;
for (int i = 0; i < coefficients.size(); i++)
value += coefficients[i] * power_x;
power_x *= x;
cout << "The value of the polynomial at x = " << x << " is " << value << endl;
system ("pause");
}
嗨,写一个程序来计算x的值与增加的多项式,这里是我的计划,我的教授要我输入以下内容作为输入:
1 0 1为系数 1.5为x的值 但我的输出给了我2而不是3.25这是正确的答案。求x的值多项式C++