Home > Palm > Samples > Combination > Pascal
 
  Palm sample in Pascal

 Purpose

This is the Pascal version of our combination application. It's one of the Palm Samples.

 Requirements

You need HSPascal, a.k.a. High-Speed Pascal (see tools section).

 Source code

Below is the .pas file.

For .prc, please download the ZIP file.

Program CombinationSample;

{$ApplName Comb-HSP,CoHS}

Uses Crt, HSUtils, Field, Form, DataMgr, MemoryMgr;

Resource Alert1=(ResTalt,,0,,0,'Combination','^1','Ok');

Function Factorial(n:integer) : integer;
Begin
     If (n <= 1)
        Then Factorial :=  1
        Else Factorial := n * Factorial(n-1);   // let's use recursion here
End;

Function Combination(n:integer; p:integer) : integer;
Begin
     Combination := Factorial(n) Div (Factorial(n - p) * Factorial(p));
End;

Var Buffer: String[20];
    Button: Integer;

Begin
  Writeln('Combination > Palm > HSPascal');
  Writeln('');

  Str(Factorial(7), Buffer);
  Writeln('Factorial(7) = ' + Buffer);

  Str(Factorial(4), Buffer);
  Writeln('Factorial(4) = ' + Buffer);

  Str(Factorial(3), Buffer);
  Writeln('Factorial(3) = ' + Buffer);

  Str(Combination(7,4), Buffer);
  Writeln('Combination(7,4) = ' + Buffer);

  Button := FrmCustomAlert(Alert1, 'OK', ' ', ' ');
end.

 Comments

HSPascal is really a great tool, just as Pascal is a great language. Note how compact the source code can be, and review the ports of combination to other languages.

As a matter of fact, the whole program is limited to the core functions: Factorial(), Combination() and CombinationSample().

Next sample

 

[ Copyright © 2000- Eric Poncet - All rights reserved ]

[ Stages de musique ]

[ Stage de musique classique | Stage de musique baroque | Stage de musique de chambre | Stage de musique latine ]
[ Stage de jazz | Stage de musiques actuelles | Stage de funk | Stage de metal | Stage de pop | Stage de reggae | Stage de rock ]
[ Stage d'improvisation | Colonie musicale ]