Sei sulla pagina 1di 2

#include<stdio.

h>

#include<math.h>

int evaluate(int arr[],int limit,int x)

int sum=0,count;

for(count=limit;count>=0;count--)

sum=sum+arr[count]*pow(x,count);

return sum;

int main()

int array[30],degree,x,count,result;

printf("\nEnter the degree of polynomial:\t");

scanf("%d",&degree);

printf("\nEnter the Co-efficients:\n");

for(count=degree;count>=0;count--)

printf("\nCo-efficient of A[%d]:\t",degree);

scanf("%d",&array[count]);

printf("\nThe polynomial:\n\n");

for(count=degree;count>=0;count--)

if(array[count]!=0)

printf("%dX^%d + ",array[count],count);

printf("%d",array[count]);
printf("\n\nEnter the value of X:\t");

scanf("%d",&x);

result=evaluate(array,degree,x);

printf("\nEvaluation of Polynomial:\t%d\n",result);

return 0;

//Output

Enter the degree of polynomial: 4

Enter the Co-efficients:

Co-efficient of A[4]: 3

Co-efficient of A[4]: 4

Co-efficient of A[4]: 6

Co-efficient of A[4]: 2

Co-efficient of A[4]: 5

The polynomial:

3X^4 + 4X^3 + 6X^2 + 2X^1 + 5X^0 + 4

Enter the value of X: 3

Evaluation of Polynomial: 416

Potrebbero piacerti anche