Advertisement
X-88

segitiga.pas

Oct 6th, 2022 (edited)
841
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 2.02 KB | Source Code | 0 0
  1. program ZP;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. uses
  6.   {$IFDEF UNIX}
  7.   cthreads,
  8.   {$ENDIF}
  9.   Classes, SysUtils, crt, CustApp;
  10.   { you can add units after this }
  11.  
  12. type
  13.  
  14.   { TMyApplication }
  15.  
  16.   TMyApplication = class(TCustomApplication)
  17.   protected
  18.     procedure DoRun; override;
  19.   public
  20.     constructor Create(TheOwner: TComponent); override;
  21.     destructor Destroy; override;
  22.     procedure WriteHelp; virtual;
  23.   end;
  24.  
  25. { TMyApplication }
  26. //global variable
  27. var
  28.   i, j, sum, total: integer;
  29.   s: string;
  30. procedure TMyApplication.DoRun;
  31. var
  32.   ErrorMsg: String;
  33. begin
  34.   // quick check parameters
  35.   ErrorMsg:=CheckOptions('h', 'help');
  36.   if ErrorMsg<>'' then begin
  37.     ShowException(Exception.Create(ErrorMsg));
  38.     Terminate;
  39.     Exit;
  40.   end;
  41.  
  42.   // parse parameters
  43.   if HasOption('h', 'help') then begin
  44.     WriteHelp;
  45.     Terminate;
  46.     Exit;
  47.   end;
  48.  
  49.   { body }
  50.   textColor($02);
  51.   write('Zephio Test', #13#10, 'Segitiga dengan jumlah', #13#10, '=======================================', #13#10);
  52.   textColor($06);
  53.   i := 0;
  54.   j := 0;
  55.   s := '';
  56.   sum := 0;
  57.   total := 0;
  58. //repeat
  59. while (i <= 10) do
  60. begin
  61.   i := i + 1;
  62.   s := s + IntToStr(j);
  63.   //WriteLn(i, '. ', s ,chr($20), '[', sum, ']');
  64.   writeln(Format('No: %.*d  Sum: [%.*d] pattern: %s', [2, i, 2, sum, s]));
  65.   total := total + sum;
  66.   sum := sum + i;
  67.   inc(j);
  68. end;
  69. //until i = 10;
  70. textcolor($07);
  71.   writeln('=======================================', #13#10, 'Total: ', total);
  72. while true do
  73.   sleep(100);
  74.   // stop program loop
  75.   Terminate;
  76. end;
  77.  
  78. constructor TMyApplication.Create(TheOwner: TComponent);
  79. begin
  80.   inherited Create(TheOwner);
  81.   StopOnException:=True;
  82. end;
  83.  
  84. destructor TMyApplication.Destroy;
  85. begin
  86.   inherited Destroy;
  87. end;
  88.  
  89. procedure TMyApplication.WriteHelp;
  90. begin
  91.   { add your help code here }
  92.   writeln('Usage: ', ExeName, ' -h');
  93. end;
  94.  
  95. var
  96.   Application: TMyApplication;
  97. begin
  98.   Application:=TMyApplication.Create(nil);
  99.   Application.Title:='Zephio Test';
  100.   Application.Run;
  101.   Application.Free;
  102. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement