C program to evaluate the polynomial P(x) = anxn + an-1xn-1 + … + a0

You are given a polynomial of degree n. The polynomial is of the form P(x) = anxn + an-1xn-1 + … + a0, where the ai‘s are the coefficients.  Given an integer x, write a program that will evaluate P(x).



You are provided with a function named power( ) that takes two positive integers x & y and returns xy. If y is 0, the function returns 1.

The prototype of this function is

int power(int x, int y);

You do not have to write the program for power ( ) function. This function is automatically added at the end of the code segment that you write.

INPUT:
Line 1 contains the integers n and x separated by whitespace.

Line 2 contains the coefficients an, an-1…, a0 separated by whitespace.

OUTPUT:
A single integer which is P(x).

Implementation: