1 #include <iostream> 2 using namespace std; 3 4 int Horner(int x, int a[], int n) { 5 if(n>=0) return a[n]+x*Horner(x,a,n-1); 6 else return 0; 7 } 8 9 void main(void) { 10 int x,n,a[50]; 11 cout << "Enter X value:"; 12 cin >> x; 13 cout << "Enter Max-Exp of f(x):"; 14 cin >> n; 15 for(int i=0; i<=n; i++) 16 { 17 cout << "Value of constants X^" << n-i << ":"; 18 cin >> a[i]; 19 } 20 cout << Horner(x, a, n) << endl; 21 }
최근 댓글