Fibonacci in Pascal

Published on 24 October 2021 (Updated: 24 October 2021)

Welcome to the Fibonacci in Pascal page! Here, you'll find the source code for this program as well as a description of how the program works.

Current Solution

program Fibonacci(input, output, stdErr);
(*Read count of fibonnaci numbers into a string

*)
var
  buf: String;
  count, check, first,second,result, i : integer;

begin
  (*Variable initialisation must be inside begin-end block*)
  first := 0;
  second := 1;
  result := 0;

  begin   
   buf:= paramStr(1);
   Val(buf, count, check);  
   (*If input is valid integer, check will be 0, else will be 1*)
   if (check <> 0)
   then
   begin
    writeln('Usage: please input the count of fibonacci numbers to output');
   end
   else
    for i := 1 to count do
    begin
    
    result := first + second;
    first := second;
    second := result;
    writeln(i, ': ', first);
    end;
   end;
end.

Fibonacci in Pascal was written by:

If you see anything you'd like to change or update, please consider contributing.

How to Implement the Solution

No 'How to Implement the Solution' section available. Please consider contributing.

How to Run the Solution

No 'How to Run the Solution' section available. Please consider contributing.