#include#include #include void accept_poly(int [],int); void display_poly(int [],int); void eval_poly(int [],int); void main() { int a[10],t; clrscr(); printf("\n How Many Degree: "); scanf("%d",&t); printf("\ Enter The Polynomial Order: "); accept_poly(a,t); printf("\n Polynomial is: "); display_poly(a,t); eval_poly(a,t); getch(); } void accept_poly(int a[],int t) { int i; for(i=t; i>=0;i--) { printf("\n Enter Coeff of Degree x^%d: ",i); scanf("%d",&a[i]); } } void display_poly(int a[],int t) { int i; for(i=t;i>0;i--) { printf("%dx%d + ",a[i],i); } printf("%dx%d",a[i],i); } void eval_poly(int a[],int t) { int i,x,ans=0; printf("\n Enter Value For x : "); scanf("%d",&x); for(i=t;i>=0;i--) { ans=ans+a[i]*pow(x,i); } printf("\n Evaluation of Polynomial: %d",ans); } /*OUTPUT How Many Degree: 3 Enter The Polynomial Order: Enter Coeff of Degree x^3: 2 Enter Coeff of Degree x^2: 4 Enter Coeff of Degree x^1: 3 Enter Coeff of Degree x^0: 1 Polynomial is: 2x3 + 4x2 + 3x1 + 1x0 Enter Value For x : 2 Evaluation of Polynomial: 39 How Many Degree: 2 Enter The Polynomial Order: Enter Coeff of Degree x^2: 2 Enter Coeff of Degree x^1: 3 Enter Coeff of Degree x^0: 1 Polynomial is: 2x2 + 3x1 + 1x0 Enter Value For x : 2 Evaluation of Polynomial: 15 */
Write a C Program To Evaluate a Given Polynomial Using Function. (Use Array)
Reviewed by
on
November 16, 2013
Rating: