bukan, 11 tuh angka maksimal nge loopingnya atau lebarnya dan margin si pohon natal.
sebenernya yang menentukan juga lebar pohon natalnya sih si jbsegitiga.
tuh udah dibenerin, biar lebih bisa dibaca.
Lazarus Version:
program Project1;
{$mode objfpc}{$H+}
uses
{$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads,
{$ENDIF}{$ENDIF}
Classes, SysUtils, CustApp
{ you can add units after this };
type
{ TMyApplication }
TMyApplication = class(TCustomApplication)
protected
procedure DoRun; override;
public
constructor Create(TheOwner: TComponent); override;
destructor Destroy; override;
procedure WriteHelp; virtual;
end;
const lebar = 23;
jbsegitiga = 5;
{ TMyApplication }
procedure TMyApplication.DoRun;
var
ErrorMsg: String;
var a,b,c,cntr,spc : integer;
begin
// quick check parameters
ErrorMsg:=CheckOptions('h','help');
if ErrorMsg<>'' then begin
ShowException(Exception.Create(ErrorMsg));
Halt;
end;
// parse parameters
if HasOption('h','help') then begin
WriteHelp;
Halt;
end;
{ add your program here }
// *
// * *
// * *
// *** ***
// * *
// * *
// **** ****
// * *
// * *
// ***** *****
// * *
// * *
// ***
cntr := ((lebar div 2) + (lebar mod 2));
spc := 1;
// pucuk
for b := 1 to cntr-1 do
write(' ');
write('*');
writeln;
// pohon
for c := 1 to 3 do
begin
for a := 1 to jbsegitiga do
begin
for b := 1 to lebar do
if (b = cntr-spc) or (b = cntr+spc) or
((a = jbsegitiga) and (b> cntr-spc) and (b<cntr+spc)
and (b <> cntr))
then
write('*')
else Write(' ');
inc(spc);
writeln;
end;
dec(spc,2);
end;
// tangkai
for a := 1 to 4 do
begin
for b := 1 to lebar do
if (b = cntr+1) or (b = cntr-1) or
((a = 4) and (b = cntr))
then
write('*')
else Write(' ');
writeln;
end;
readln;
// stop program loop
Terminate;
end;
constructor TMyApplication.Create(TheOwner: TComponent);
begin
inherited Create(TheOwner);
StopOnException:=True;
end;
destructor TMyApplication.Destroy;
begin
inherited Destroy;
end;
procedure TMyApplication.WriteHelp;
begin
{ add your help code here }
writeln('Usage: ',ExeName,' -h');
end;
var
Application: TMyApplication;
begin
Application:=TMyApplication.Create(nil);
Application.Title:='My Application';
Application.Run;
Application.Free;
end.