vj1116 一元三次方程æ&p

Vj1116 一元三次方程æ&p

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
const zero=1e-3; var a,b,c,d,x1,x2:real; function f(x:real):real; begin exit(a*x*x*x+b*x*x+c*x+d); end; function calc(l,r:real):real; var mid:real; begin if abs(l-r)<zero then exit(l); mid:=(l+r)/2; if f(l)*f(mid)>0 then exit(calc(mid,r)) else exit(calc(l,mid));
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: end; procedure main; begin readln(a,b,c,d); x1:=(-2*b-sqrt(4*b*b-12*a*c))/(6*a); x2:=(-2*b+sqrt(4*b*b-12*a*c))/(6*a); write(calc(-100,x1):0:2,' '); write(calc(x1,x2):0:2,' '); writeln(calc(x2,100):0:2); end; begin main; end....
View Full Document

This note was uploaded on 02/21/2011 for the course CS 001 taught by Professor 001 during the Spring '11 term at Shandong University.

Ask a homework question - tutors are online