Thursday, April 2, 2020

FIBONACC.P

[Table of Contents]
Disk Image



FIBONACC.P is a short program from page 123 of the book "Introduction To PASCAL (Including UCSD PASCAL) Second Edition Revised" by Rodnay Zaks and published by Sybex.

This program demonstrates how to use recursion in PASCAL. Recursion is the ability of a function or procedure to repeatedly call itself until some condition is met.

What's on the disk?


The disk image includes the various Atari DOS 2.5 files, Kyan Pascal Include files (none of which are used in this program), Kyan Pascal Run-time library, and ...

FIBONACC.P
- Source code file
P.OUT - Kyan Pascal intermediate file
FIBONACC - Executable file

Source Code


(* Fibonacc.p *)
(* Kyan Pascal 2.x / Atari 8-bit *)

Program Fibonacc(Input,Output);

(* Program to calculate Fibonacci numbers given *)
(* its place in the series *)

VAR
   Fibnum : Integer;

Function Fib(Count:Integer):Integer;
Begin (* Fib *)
   If Count > 1 Then
      Fib:= Fib(Count-1) + Fib(Count-2)
   Else If
      Count = 1 Then Fib:=1
   Else
      Fib:=0
END; (* Fib *)

(* Main Program *)
Begin (* Fibonacci *)
   Write(Chr(125)); (* Clear the screen *)
   Repeat
      Write('Enter a number: ');
      Readln(Fibnum);
   Until Fibnum >=0;
   Writeln('The Fibonacci number is ', Fib(Fibnum));
   Writeln;
   Write('Press <RETURN> key to exit program.');
   Readln;
End. (* Fibonacci *)

Sample Run




No comments:

Post a Comment