Issue with Horner's polynomial c program
Code:
#include<stdio.h>
#include<conio.h>
int horner(int,int);
int count=0;
void main()
{
/*Horner's rule for evaluating a polynomial */
/* let us take a0=0,a1=1,a2=2.. and so on */
int n,x,h=0; //n is order, x is value of X in polynomial.
scanf("%d %d",&n,&x);
h=horner(n,x);
printf("%d",h);
getch();
}
int horner(int n, int x)
{
if(count!=n)
{
count++;
printf("%d+%d*(",count-1,x);
return (count-1 + x*horner(n,x));
}
else
{
printf("%d))=",count);
return count;
}
}
Can anybody help me in finding the issues with above program of evaluating a polynomial with horner's rule? I think the program is correct but it shows errornous output