Add some more Pascal

This commit is contained in:
Timothy Warren 2021-09-17 16:16:48 -04:00
parent b167eb3327
commit ebb0dd62a8
4 changed files with 47 additions and 2 deletions

20
pascal/Factorial.pas Normal file
View File

@ -0,0 +1,20 @@
program Factorial;
var input: Word;
function Fact (n: word): NativeUInt;
begin
case n of
0: Fact := 0;
1: Fact := 1;
else Fact := n * Fact(n - 1)
end;
end;
begin
Write('Which Factorial to calculate? ');
ReadLn(input);
WriteLn(Fact(input));
end.

25
pascal/Fib2.pas Normal file
View File

@ -0,0 +1,25 @@
{ Prints Fibonacci Number supplied }
program Fib2;
const
ZERO = 1;
ONE = 1;
var
input: word;
function Fib (n: word): NativeUInt;
begin
case n of
0: Fib := 0;
1, 2: Fib := 1;
else Fib := Fib(n - 2) + Fib(n - 1)
end;
end;
begin
write('Which Fibonacci number would you like? ');
readln(input);
WriteLn(Fib(input));
end.

View File

@ -3,7 +3,7 @@ PROGRAMS_O = $(patsubst %.pas,%.o,$(PROGRAMS_SRC))
PROGRAMS = $(patsubst %.pas,%,$(PROGRAMS_SRC))
all:
$(foreach file, $(PROGRAMS), fpc ${file};)
$(foreach file, $(PROGRAMS), fpc -v0 ${file};)
clean:
rm -f $(PROGRAMS_O)

View File

@ -23,7 +23,7 @@ begin
case i of
15: writeln(this:6);
5, 10: writeln(this:6, ',');
otherwise write(this:6, ', ')
else write(this:6, ', ')
end;
end;
end.