Given a polynomial of the form cnxn + cn-1xn-1 + cn-2xn-2 + … + c1x + c0 and a value of x, find the value of polynomial for a given value of x. Here cn, cn-1, .. are integers (may be negative) and n is a positive integer.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def hornerRule(poly,n,x): | |
result=poly[0] | |
for i in range(1,n): | |
result=result*x+poly[i] | |
return result | |
arr=list(map(int,input().split)) | |
x=int(input()) | |
len=len(arr) | |
print(hornerRule(arr,len,x)) |
Comments
Post a Comment
Please give us your valuable feedback