Program to find the value of P ( N + r ) for a polynomial of a degree N such that P ( i ) = 1 for 1 Ã ¢ â €°¤ i Ã ¢ â €°¤ N and P ( N + 1 ) = a | Function to calculate factorial of N ; Base Case ; Otherwise , recursively calculate the factorial ; Function to find the value of P ( n + r ) for polynomial P ( X ) ; Stores the value of k ; Store the required answer ; Iterate in the range [ 1 , N ] and multiply ( n + r - i ) with answer ; Add the constant value C as 1 ; Return the result ; Driver code
function fact ( n ) { if ( n == 1 n == 0 ) return 1 ; else return n * fact ( n - 1 ) ; } function findValue ( n , r , a ) { let k = ( a - 1 ) / fact ( n ) ; let answer = k ; for ( let i = 1 ; i < n + 1 ; i ++ ) answer = answer * ( n + r - i ) ; answer = answer + 1 ; return answer ; } let N = 1 ; let A = 2 ; let R = 3 ; document . write ( findValue ( N , R , A ) ) ;