0hc.net Menu
Home Overview
About Menu
Impressum

Polynomial

A program to evaluate a polynomial function of any order: main = getLine >>= \li -> (\(x:xs) -> print (foldr (\s t -> s+x*t) 0 xs)) (map read (words li)) It's really just one line! How it works: To Solve: p(x)=0+2*x+2*x^2 for p(5) input: 5 0 2 2 and 60 will be printed. Another example: 2*x^0+1*x^1+7*x^2; x=10 (2+x+7*x^2) would be: 10 2 1 7 and the result: 712
0hc.net    © 2001-2014 Harald Wolfsgruber