text: Sgn value of a polynomial | CPP program to find sign value of a polynomial ; returns value of poly [ 0 ] x ( n - 1 ) + poly [ 1 ] x ( n - 2 ) + . . + poly [ n - 1 ] ; Evaluate value of polynomial using Horner 's method ; Returns sign value of polynomial ; Driver program to test above function . ; Let us evaluate value of 2 x3 - 6 x2 + 2 x - 1 for x = 3
code: #include <iostream> NEW_LINE using namespace std ; int horner ( int poly [ ] , int n , int x ) { for ( int i = 1 ; i < n ; i ++ ) result = result * x + poly [ i ] ; return result ; } int findSign ( int poly [ ] , int n , int x ) { int result = horner ( poly , n , x ) ; if ( result > 0 ) return 1 ; else if ( result < 0 ) return -1 ; return 0 ; } int main ( ) { int poly [ ] = { 2 , -6 , 2 , -1 } ; int x = 3 ; int n = sizeof ( poly ) / sizeof ( poly [ 0 ] ) ; cout << " Sign ▁ of ▁ polynomial ▁ is ▁ " << findSign ( poly , n , x ) ; return 0 ; }