Add some more Pascal
This commit is contained in:
parent
b167eb3327
commit
ebb0dd62a8
|
@ -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.
|
|
@ -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.
|
|
@ -3,7 +3,7 @@ PROGRAMS_O = $(patsubst %.pas,%.o,$(PROGRAMS_SRC))
|
||||||
PROGRAMS = $(patsubst %.pas,%,$(PROGRAMS_SRC))
|
PROGRAMS = $(patsubst %.pas,%,$(PROGRAMS_SRC))
|
||||||
|
|
||||||
all:
|
all:
|
||||||
$(foreach file, $(PROGRAMS), fpc ${file};)
|
$(foreach file, $(PROGRAMS), fpc -v0 ${file};)
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f $(PROGRAMS_O)
|
rm -f $(PROGRAMS_O)
|
||||||
|
|
|
@ -23,7 +23,7 @@ begin
|
||||||
case i of
|
case i of
|
||||||
15: writeln(this:6);
|
15: writeln(this:6);
|
||||||
5, 10: writeln(this:6, ',');
|
5, 10: writeln(this:6, ',');
|
||||||
otherwise write(this:6, ', ')
|
else write(this:6, ', ')
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
end.
|
end.
|
Loading…
Reference in New Issue