// calculating root for polynomial: f(x) = x^3 - x - 2
read a, b, tolerance and max_iteration set i = 1 while(i <= max_iteration) set c = (a + b) / 2 if f(c)==0 or (b - a)/2 < tolerance print "Root <value-of f(c)> found after <value-of i> iterations. " stop endif if f(c) * f(a) > 0 then a = c else b = c i = i + 1 end
Notes: 1. we will using math.h for the "pow" (power - n to the x) function 2. better if enclose the math expression calculation with a function