Question

In: Computer Science

Using C++ 1) Write a program that repeatedly evaluates a n-th order polynomial p(x) = a0...

Using C++

1) Write a program that repeatedly evaluates a n-th order polynomial p(x) = a0 + a1*x + a2*x^2 + ... + an*x^n where n <= 10 The program inputs n, ai, and x from the keyboard and then prints out the corresponding value of p to the screen. The program continues to input new values of n, ai, x and evaluates p until a negative value for n is input, at which point the program stops.

Solutions

Expert Solution

Program

#include <iostream>
#include<cmath>
using namespace std;

//main function
int main()
{
//variable declaration
double a[11], x;
int n;
//processing
while(1)
{
//prompt and read the order of the polynomial
cout<<"Enter n: ";
cin >> n;
//check if n is negative
if(n<0) break;
//read the coefficients of the polynomial
for(int i=0; i<=n; i++)
{
cout<<"Enter a"<<i<<": ";
cin>>a[i];
}
//prompt and read the value of x
cout<<"Enter x: ";
cin>>x;
//calculate the value of the polynomial
double sum = 0;
for(int i=0; i<=n; i++)
{
sum += a[i]*pow(x, i);
}
//display the value of the polynomial
cout<<"The value of the polynomial: "<<sum<<endl;
}

return 0;
}

Output:

Solving your question and helping you to well understand it is my focus. So if you face any difficulties regarding this please let me know through the comments. I will try my best to assist you. However if you are satisfied with the answer please don't forget to give your feedback. Your feedback is very precious to us, so don't give negative feedback without showing proper reason.
Always avoid copying from existing answers to avoid plagiarism.
Thank you.


Related Solutions

find the n-th order Taylor polynomial and the remainder for f(x)=ln(1+x) at 0
find the n-th order Taylor polynomial and the remainder for f(x)=ln(1+x) at 0
Let P(x) be a polynomial of degree n and A = [an , an-1,.... ] Write...
Let P(x) be a polynomial of degree n and A = [an , an-1,.... ] Write a function integral(A, X1, X2) that takes 3 inputs A, X0 and X1 A as stated above X1 and X2 be any real number, where X1 is the lower limit of the integral and X2 is the upper limit of the integral. Please write this code in Python.
Let P(x) be a polynomial of degree n and A = [an , an-1,.... ] Write...
Let P(x) be a polynomial of degree n and A = [an , an-1,.... ] Write a function integral(A, X1, X2) that takes 3 inputs A, X0 and X1 A as stated above X1 and X2 be any real number, where X1 is the lower limit of the integral and X2 is the upper limit of the integral. Please write this code in Python. DONT use any inbuilt function, instead use looping in Python to solve the question. You should...
p(x) = a0 + a1x + a2x2 + · · · + akxk is a polynomial...
p(x) = a0 + a1x + a2x2 + · · · + akxk is a polynomial of degree k. What is the Taylor series of p(x), and its radius and interval of convergence.
C++ DO not use arrays to write this program. Write a program that repeatedly generates three...
C++ DO not use arrays to write this program. Write a program that repeatedly generates three random integers in the range [1, 100] and continues as follows: If the right-most digit of all the three integers is equal, the program displays them in ascending order on the screen and continues. If the generated integers have different right-most digits, they are not displayed and the program continues. The program terminates once the right-most digits of all the three random numbers are...
Write a C program that evaluates the factorials from 1 to 5. Print results in a...
Write a C program that evaluates the factorials from 1 to 5. Print results in a tabular format.
write an algorithm program using python or C++ where a0=1, a1=2 an=an-1*an-2, find an ,also a5=?
write an algorithm program using python or C++ where a0=1, a1=2 an=an-1*an-2, find an ,also a5=?
Given n ∈N and p prime number and consider the polynomial f (x) = xn (xn-2)+1-p...
Given n ∈N and p prime number and consider the polynomial f (x) = xn (xn-2)+1-p 1)Prove that f (x) is irreducible in Q [x] 2) If n = 1 and p = 3, find Q [x] / f (x)) 3) Show that indeed Q [x] / (f (x)) is a field in the previous paragraph PLEASE answer all subsections
: In this assignment you will write a C++ program that evaluates an arithmetic expression (represented...
: In this assignment you will write a C++ program that evaluates an arithmetic expression (represented with an infix notation), then outputs this expression in prefix form and also outputs the result of the calculation. The program will first convert the input infix expression to a prefix expression (using the Stack ADT) and then calculate the result (again, using the Stack ADT). The details are provided in the following sections.
write this program in c++ using iostream library.( cin>>n; cin>> arr[n] and so on) Write a...
write this program in c++ using iostream library.( cin>>n; cin>> arr[n] and so on) Write a function that converts an array so that in the first half settled with elements from odd positions, and in the second half - with elements from the even positions.Positions are counted from the first index.The program have to use pointer. example: input: 7 1 2 3 4 5 6 7 output: 1 3 5 7 2 4 6 8
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT