function f(x,d) { return x*x-d;} function f3() { a = Number(document.getElementById('a').value); b = Number(document.getElementById('b').value); d = Number(document.getElementById('d').value); e = Number(document.getElementById('e').value); if ((a==b) || (e<=0)) s = "Хибні вхідні дані!"; else { fa = f(a,d); if (fa == 0) s = "x = " + a; fb = f(b,d); if (fb == 0) s = "x = " + b; if (fa*fb > 0) s = "Ймовірно, коренів немає."; if (fa*fb < 0) { fc = fa; while ((Math.abs(b-a) >= e) && (fc!=0)) { c = (a+b)/2; fc = f(c,d); if (fc*fa > 0) a = c; else b = c; } s = "x = "+c; } } document.getElementById('res').innerHTML = s; }