Advertisement
finalshare

PT

Aug 1st, 2015
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 3.79 KB | None | 0 0
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,math;
  9.  
  10. type
  11.  
  12.   { TForm1 }
  13.  
  14.   TForm1 = class(TForm)
  15.     a1: TEdit;
  16.     b1: TEdit;
  17.     Button1: TButton;
  18.     c1: TEdit;
  19.     d1: TEdit;
  20.     Label1: TLabel;
  21.     Label2: TLabel;
  22.     Label3: TLabel;
  23.     Label4: TLabel;
  24.     x22: TLabel;
  25.     x33: TLabel;
  26.     x11: TLabel;
  27.     songhiem: TLabel;
  28.     procedure Button1Click(Sender: TObject);
  29.   private
  30.     { private declarations }
  31.   public
  32.     { public declarations }
  33.   end;
  34.  
  35. var
  36.   Form1: TForm1;
  37.   delta,k:real;
  38.   x1,x2,x3:real;
  39.   a,b,c,d:real;
  40.   part1,part2,part3:real;
  41.  
  42.  
  43. implementation
  44.  
  45. {$R *.lfm}
  46.  
  47. { TForm1 }
  48. procedure TForm1.Button1Click(Sender: TObject);
  49. begin
  50.   a:=strtofloat(a1.Text);
  51.   b:=strtofloat(b1.Text);
  52.   c:=strtofloat(c1.Text);
  53.   d:=strtofloat(d1.Text);
  54.  
  55.   if a<> 0 then
  56.   begin
  57.        delta:=b*b-3*a*c;
  58.        if delta <> 0 then
  59.            begin
  60.                 k:=(9*a*b*c-2*b*b*b-27*a*a*d)/(2*sqrt(abs(delta*delta*delta)));
  61.            end
  62.        else
  63.            begin
  64.                 x1:=(-b+power(b*b*b-27*a*a*d,1/3))/(3*a);
  65.                 songhiem.caption:='Phương trình có 1 nghiệm.';
  66.                 x11.Caption:='x1= '+floattostr(x1);
  67.            end;
  68.        if delta<0 then
  69.           begin
  70.                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);
  71.                songhiem.caption:='Phương trình có 1 nghiệm.';
  72.                x11.Caption:='x1= '+floattostr(x1);
  73.           end;
  74.        if (delta>0) and (abs(k)>1) then
  75.           begin
  76.                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);
  77.                songhiem.caption:='Phương trình có 1 nghiệm.';
  78.                x11.Caption:='x1= '+floattostr(x1);
  79.           end;
  80.        if (delta>0) and (abs(k)<=1) then
  81.           begin
  82.                x1:=(2*sqrt(delta)*cos(arccos(k)/3)-b)/(3*a);
  83.                x2:=(2*sqrt(delta)*cos(arccos(k)/3-(2*pi)/3)-b)/(3*a);
  84.                x3:=(2*sqrt(delta)*cos(arccos(k)/3+(2*pi)/3)-b)/(3*a);
  85.                songhiem.caption:='Phương trình có 3 nghiệm.';
  86.                x11.Caption:='x1= '+floattostr(x1);
  87.                x22.Caption:='x2= '+floattostr(x2);
  88.                x33.Caption:='x3= '+floattostr(x3);
  89.           end;
  90.  
  91.   end;
  92.   if a=0 then
  93.      begin
  94.           if b <> 0 then
  95.              begin
  96.                   delta:=(c*c)-(4*b*d);
  97.                   if delta<0 then
  98.                      songhiem.caption:='Phương trình vô nghiệm.';
  99.                   if delta=0 then
  100.                      begin
  101.                        x1:=-b/(2*a);
  102.                        songhiem.caption:='Phương trình có 1 nghiệm.';
  103.                        x11.caption:='x1= '+floattostr(x1);
  104.                      end;
  105.                   if delta>0 then
  106.                      begin
  107.                        x1:=(-b+sqrt(delta))/(2*a);
  108.                        x2:=(-b-sqrt(delta))/(2*a);
  109.                        songhiem.caption:='Phương trình có 2 nghiệm.';
  110.                        x11.caption:='x1= '+floattostr(x1);
  111.                        x22.caption:='x2= '+floattostr(x2);
  112.                      end;
  113.              end;
  114.           if b=0 then
  115.              begin
  116.                if c <> 0 then
  117.                   begin
  118.                        x1:=-d/c;
  119.                        songhiem.caption:='Phương trình có 1 nghiệm.';
  120.                        x11.caption:='x1= '+floattostr(x1);
  121.                   end;
  122.                if (c=0) and (d<>0) then songhiem.caption:='Phương trình vô nghiệm.';
  123.                if (c=0) and (d=0) then songhiem.caption:='Phương trình vô sô nghiệm.';
  124.              end;
  125.      end;
  126. end;
  127. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement