Треугольник Паскаля И Лейбница(delphi)

tane

New Member
17.12.2013
1
0
#1
Нашел 2 кода.Паскаль
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}
function F(x,y:integer):integer;
begin
if (x=1)or(y=1)then F:=1
else F:=F(x-1,y)+F(x,y-1);
end;
procedure TForm1.Button1Click(Sender: TObject);
var n,i,j,k:integer;
begin
n:=Strtoint(Edit1.Text);
for i:=1 to n do
begin
for k:=1 to 2*(n-i)+1 do
label1.Caption:=label1.Caption+ ' ';
for j:=1 to i do
label1.Caption:=label1.Caption + inttostr(F(j,i-j+1))+' ';
label1.Caption:=label1.Caption+#13+#10;
end;
end;

end.

Треугольник Лейбница

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Forms;

type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormPaint(Sender: TObject);
private
{ Private declarations }
TextSize: TSize;
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

uses Math;

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
Font.Name:='Courier New';
GetTextExtentPoint32(Canvas.Handle,'0',1,TextSize);
DoubleBuffered:=True;
OnResize:=FormPaint;
end;

procedure TForm1.FormPaint(Sender: TObject);
var BitMap: TBitmap;
n,i,k,j,m,t: Integer;
a: array of Integer;
xRect: TRect;
begin
BitMap:=TBitmap.Create;
BitMap.Height:=ClientHeight;
BitMap.Width:=ClientWidth;
n:=ClientHeight div (TextSize.cy*2);
SetLength(a,n);
for i:=n downto 1 do begin
k:=i;
for j:=0 to (i-1) div 2 do begin
a[j]:=k;
a[i-1-j]:=k;
k:=(k*(i-1-j)) div (j+1);
end;
if i=n then m:=Length(IntToStr(a[(i-1) div 2]));
k:=((n-i)*(m+1)*TextSize.cx) div 2;
for j:=0 to i-1 do begin
xRect:=Rect(k,(i-1)*TextSize.cy*2+TextSize.cy,k+m*TextSize.cx,(i-1)*TextSize.cy*2+TextSize.cy*2);
DrawText(BitMap.Canvas.Handle,PChar(IntToStr(a[j])),Length(IntToStr(a[j])),xRect
,DT_CENTER);
if i>1 then begin
xRect:=Rect(k,(i-1)*TextSize.cy*2,k+m*TextSize.cx,(i-1)*TextSize.cy*2+TextSize.cy);
DrawText(BitMap.Canvas.Handle,'1',1,xRect,DT_CENTER);
t:=Length(IntToStr(a[j]))*TextSize.cx;
BitMap.Canvas.MoveTo(k+(m*TextSize.cx-t) div 2,(i-1)*TextSize.cy*2+TextSize.cy);
BitMap.Canvas.LineTo(k+(m*TextSize.cx-t) div 2+t,(i-1)*TextSize.cy*2+TextSize.cy);
end;
Inc(k,(m+1)*TextSize.cx);
end;
end;
Canvas.Draw(0,0,BitMap);
BitMap.Free;
end;

end.

Блин,это бы упростить и структурировать!
Заранее благодарю!


Добавлено: Нужен максимально простой код(я новичок)