Evaluating a polynomial at a given value of x and n To solve a polynomial equation I have written following program, is there any way to optimize this program.

Following code is working code:

Program takes input n,x where n is the deg of polynomial and x is the point at which the polynomial is to be evaluated.

   #include&lt;stdio.h&gt;

   int power(int x, int y);

   int main()
  {
  // n is the deg of polynomial
  // x is the value of polynomial for which it is to be evaluated
  int x=0,n=0,A[10],sum=0,i=0,M=0,y=0;

  printf("Enter value of n,x \n");
  scanf("%d %d",&amp;n,&amp;x);

  printf("Enter the coeficients\n");

  for(i=0;i&lt;=n;i++)          //Taking coefiecent values
  {
     scanf("%d",&amp;A[i]);
  }

  y=n;
  for(i=0;i&lt;=n;i++)
  {
    M=power(x,y);
    sum=sum+(A[i]*M);
    y--;
   }

  printf("\nSum of polynomial is %d",sum);

  return 0;
 }


 int power(int x, int y)
 {
  int result = x;
  int i;
  if(y == 0) return 1;
  if(x &lt; 0 || y &lt; 0) return 0;

  for(i = 1; i &lt; y; ++i)
  result *= x;

  return result;
}
By following Horner's Method only n multiplications are needed.

#include &lt;stdio.h&gt;

int main()
{
   // n is the deg of polynomial
   // x is the value of polynomial for which it is to be evaluated
   int x=0,n=0,A[10],b,i;

   printf("Enter value of n,x \n");
   scanf("%d %d",&amp;n,&amp;x);

   //Taking coefficient values
   printf("Enter the coeficients\n");

   for(i=0;i&lt;=n;i++) scanf("%d",&amp;A[i]);

   for(i = n - 1,b = A[n];i &gt;= 0;i--) b = b*x + A[i];

   printf("\nSum of polynomial is %d\n",b);

   return 0;
}