var
a,b,c:integer;
p:int64;
x1,x2:string;
begin
a:=strtoint(edit1.Text);
b:=strtoint(edit2.Text);
c:=strtoint(edit3.Text);
p:=b*b-4*a*c;
edit6.Text:=floattostr(p);
if p>=0 then
begin
try
x1:=floattostr(-b/2+sqr(p));
x2:=floattostr((-b/2-sqr(p));
edit4.Text:=x1;
edit5.Text:=x2;
except
showmessage('溢出');
end;
if p<0 then
begin
try
x1:=floattostr(-b/2)+'i'+floattostr(sqr(-p));
x2:=floattostr(-b/2)+'-'+'i'+floattostr(sqr(-p));
edit4.Text:=x1;
edit5.Text:=x2;
except
showmessage('溢出');
end;
end; end;
end;
计算出来的结果跟实际的不相符
a,b,c:integer;
p:int64;
x1,x2:string;
begin
a:=strtoint(edit1.Text);
b:=strtoint(edit2.Text);
c:=strtoint(edit3.Text);
p:=b*b-4*a*c;
edit6.Text:=floattostr(p);
if p>=0 then
begin
try
x1:=floattostr(-b/2+sqr(p));
x2:=floattostr((-b/2-sqr(p));
edit4.Text:=x1;
edit5.Text:=x2;
except
showmessage('溢出');
end;
if p<0 then
begin
try
x1:=floattostr(-b/2)+'i'+floattostr(sqr(-p));
x2:=floattostr(-b/2)+'-'+'i'+floattostr(sqr(-p));
edit4.Text:=x1;
edit5.Text:=x2;
except
showmessage('溢出');
end;
end; end;
end;
计算出来的结果跟实际的不相符
x1:=FloatToStr((-b+sqrt(p))/(2*a));
x2:=FloatToStr((-b-sqrt(p))/(2*a));
虚数那部分以此类推.
可是虚数不能计算
而且
好象还捕获不到异常
if p<0 then
begin
try
x1:=floattostr(-b/2))+'+'+'i'+floattostr(sqr(-p));
x2:=floattostr(-b/2)+'-'+'i'+floattostr(sqr(-p));
edit4.Text:=x1;
edit5.Text:=x2;
except
showmessage('溢出');
比如a:=1 b:=3 c;=1
计算出x1=11 x2:=11
a,b,c:integer;
p:int64;
x1,x2:string;
begin
a:=strtoint(edit1.Text);
b:=strtoint(edit2.Text);
c:=strtoint(edit3.Text);
p:=b*b-4*a*c;
edit6.Text:=floattostr(p);
if p>=0 then
begin
try
x1:=floattostr((-b+sqr(p))/2/a);
x2:=floattostr((-b-sqr(p))/2/a);
edit4.Text:=x1;
edit5.Text:=x2;
except
showmessage('溢出');
end;
if p<0 then
begin
try
x1:=floattostr(-b/2))+'+'+'i'+floattostr(sqr(-p));
x2:=floattostr(-b/2)+'-'+'i'+floattostr(sqr(-p));
edit4.Text:=x1;
edit5.Text:=x2;
except
showmessage('溢出');
end;
end; end;
end;
var
a,b,c:integer;
p:int64;
x1,x2:string;
begin
a:=strtoint(edit1.Text);
b:=strtoint(edit2.Text);
c:=strtoint(edit3.Text);
p:=b*b-4*a*c;
edit6.Text:=floattostr(p); if p>=0 then
begin
try
x1:=floattostr((-b+sqr(p))/2/a);
x2:=floattostr((-b-sqr(p))/2/a);
edit4.Text:=x1;
edit5.Text:=x2;
except
showmessage('溢出');
end
end
else
if p<0 then
begin
try
x1:=floattostr(-b/2)+'+'+'i'+floattostr(sqr(-p));
x2:=floattostr(-b/2)+'-'+'i'+floattostr(sqr(-p));
edit4.Text:=x1;
edit5.Text:=x2;
except
showmessage('溢出');
end;
end;
end;
a,b,c:integer;
p:real;
x1,x2:string;
begin
a:=strtoint(edit1.Text);
b:=strtoint(edit2.Text);
c:=strtoint(edit3.Text);
p:=b*b-4*a*c;
edit6.Text:=floattostr(p); if p>=0 then
begin
try
showmessage(floattostr(sqrt(p)));
x1:=floattostr((-b+sqrt(p))/2/a);
x2:=floattostr((-b-sqrt(p))/2/a);
edit4.Text:=x1;
edit5.Text:=x2;
except
showmessage('溢出');
end
end
else if p<0 then
begin
try
x1:=floattostr(-b/2)+'+'+'i'+floattostr(sqrt(-p));
x2:=floattostr(-b/2)+'-'+'i'+floattostr(sqrt(-p));
edit4.Text:=x1;
edit5.Text:=x2;
except
showmessage('溢出');
end;
end;
end;