Answer to Question #102861 in C++ for anu

Question #102861
As input, you are given an integer n, a double x, followed by n+1 doubles a_n, a_{n-1}, ..., a_0. You are to print the value of the polynomial a_0 + a_1x+a_2x^2+...+a_nx^n.
1
Expert's answer
2020-02-13T10:52:42-0500
#include <iostream>
#include <cmath>

using namespace std;

int main()
{
  int n;
  double x;
  double a_[50];

  double sum=0;

  cin >> n;
  cin >> x;

  for (int i=n;i>=0;i--)
  {
      cin>>a_[i];
      sum=sum+(a_[i]*pow(x,i));
  }

  cout << sum;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS