Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit Unit1;
- {$mode objfpc}{$H+}
- interface
- uses
- Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,math;
- type
- { TForm1 }
- TForm1 = class(TForm)
- a1: TEdit;
- b1: TEdit;
- Button1: TButton;
- c1: TEdit;
- d1: TEdit;
- Label1: TLabel;
- Label2: TLabel;
- Label3: TLabel;
- Label4: TLabel;
- x22: TLabel;
- x33: TLabel;
- x11: TLabel;
- songhiem: TLabel;
- procedure Button1Click(Sender: TObject);
- private
- { private declarations }
- public
- { public declarations }
- end;
- var
- Form1: TForm1;
- delta,k:real;
- x1,x2,x3:real;
- a,b,c,d:real;
- part1,part2,part3:real;
- implementation
- {$R *.lfm}
- { TForm1 }
- procedure TForm1.Button1Click(Sender: TObject);
- begin
- a:=strtofloat(a1.Text);
- b:=strtofloat(b1.Text);
- c:=strtofloat(c1.Text);
- d:=strtofloat(d1.Text);
- if a<> 0 then
- begin
- delta:=b*b-3*a*c;
- if delta <> 0 then
- begin
- k:=(9*a*b*c-2*b*b*b-27*a*a*d)/(2*sqrt(abs(delta*delta*delta)));
- end
- else
- begin
- x1:=(-b+power(b*b*b-27*a*a*d,1/3))/(3*a);
- songhiem.caption:='Phương trình có 1 nghiệm.';
- x11.Caption:='x1= '+floattostr(x1);
- end;
- if delta<0 then
- begin
- x1:=(sqrt(abs(delta))/(3*a))*(power(k+sqrt(k*k+1),1/3)-power(abs(k-sqrt(k*k+1)),1/3))-b/(3*a);
- songhiem.caption:='Phương trình có 1 nghiệm.';
- x11.Caption:='x1= '+floattostr(x1);
- end;
- if (delta>0) and (abs(k)>1) then
- begin
- x1:=((sqrt(abs(delta))*abs(k))/(3*a*k))*(power(abs(k)+sqrt(k*k-1),1/3)+power(abs(k)-sqrt(k*k-1),1/3))-b/(3*a);
- songhiem.caption:='Phương trình có 1 nghiệm.';
- x11.Caption:='x1= '+floattostr(x1);
- end;
- if (delta>0) and (abs(k)<=1) then
- begin
- x1:=(2*sqrt(delta)*cos(arccos(k)/3)-b)/(3*a);
- x2:=(2*sqrt(delta)*cos(arccos(k)/3-(2*pi)/3)-b)/(3*a);
- x3:=(2*sqrt(delta)*cos(arccos(k)/3+(2*pi)/3)-b)/(3*a);
- songhiem.caption:='Phương trình có 3 nghiệm.';
- x11.Caption:='x1= '+floattostr(x1);
- x22.Caption:='x2= '+floattostr(x2);
- x33.Caption:='x3= '+floattostr(x3);
- end;
- end;
- if a=0 then
- begin
- if b <> 0 then
- begin
- delta:=(c*c)-(4*b*d);
- if delta<0 then
- songhiem.caption:='Phương trình vô nghiệm.';
- if delta=0 then
- begin
- x1:=-b/(2*a);
- songhiem.caption:='Phương trình có 1 nghiệm.';
- x11.caption:='x1= '+floattostr(x1);
- end;
- if delta>0 then
- begin
- x1:=(-b+sqrt(delta))/(2*a);
- x2:=(-b-sqrt(delta))/(2*a);
- songhiem.caption:='Phương trình có 2 nghiệm.';
- x11.caption:='x1= '+floattostr(x1);
- x22.caption:='x2= '+floattostr(x2);
- end;
- end;
- if b=0 then
- begin
- if c <> 0 then
- begin
- x1:=-d/c;
- songhiem.caption:='Phương trình có 1 nghiệm.';
- x11.caption:='x1= '+floattostr(x1);
- end;
- if (c=0) and (d<>0) then songhiem.caption:='Phương trình vô nghiệm.';
- if (c=0) and (d=0) then songhiem.caption:='Phương trình vô sô nghiệm.';
- end;
- end;
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement