Home > Palm > Samples > Combination > PocketC Palm sample in PocketC

#### Purpose

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

#### Requirements

You need PocketC (see tools section).

#### Source code

```// Combination.c
// Palm
// PocketC

@cid "CoPC";
@ver "1.0";
@name "Comb-PC";
@dbname "CoPC";
@licon1 "large.bmp";
@sicon1 "small.bmp";

int Factorial(int n)
{
if (n <= 1)
return 1;
else return n*Factorial(n-1);
}

int Combination(int n, int p)
{
return Factorial(n)/(Factorial(n - p) * Factorial(p));
}

main()
{
int n = 0, p = 0;
char buf[10];

clear();
puts("Combination > Palm > PocketC\n\n");

n = gets("Value for 'n': ");
p = gets("Value for 'p': ");

puts("Factorial(" +n +") = " +Factorial(n) +"\n");
puts("Factorial(" +p +") = " +Factorial(p) +"\n");
puts("Factorial(" +(n-p) +") = " +Factorial(n-p) +"\n");
puts("Combination(" +n +"," +p +") = " +Combination(n,p) +"\n");
}
```

PocketC is a very valuable tool. They offer both a mobile and a desktop version of their product, not only for Palm but also for Pocket PC.

You have probably noticed that this version is sensibly shorter than the C version with Palm SDK. Also, PocketC doesn't need an extra file to describe the resources it uses. Those guys are declared at the beginning of the .c file, in the lines starting with @.

The core functions are located at the beginning of the .c file: Factorial(), Combination() and main(). Again, note that there is hardly any overhead, compared with the Palm SDK version.

Next sample