Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Catalog · How the catalog works
Anything · Lazarus or Delphi
Random projectRandom project

factorials_pascal

Factorials in Pascal!

View on GitHub

Member rating

No ratings yet.

Sign in to rate this project.

README

Factorial

A small Pascal program that calculates and prints the factorial of every integer from 0 to 16.

What it does

The program defines a recursive factorial function that computes n! using the standard recursive definition:

  • factorial(0) = 1
  • factorial(n) = n * factorial(n-1) for n > 0

The main block loops from 0 to 16, printing each value alongside its factorial.

Why 16

factorial returns a longint. Factorials grow very quickly, and 17! already exceeds the range a longint can hold, so the loop stops at 16 to avoid overflow.

Running it

Compile and run with any standard Pascal compiler, for example Free Pascal:

bash
fpc factorial.pas
./factorial

Example output

pascal
0! = 1
1! = 1
2! = 2
3! = 6
...
16! = 20922789888000

Author

blockersiontko

License

MIT