Fibonacci in Ada

Published on 10 May 2026 (Updated: 10 May 2026)

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

Current Solution

with Ada.Text_IO;       use Ada.Text_IO;
with Ada.Command_Line;  use Ada.Command_Line;
with Ada.Strings.Fixed; use Ada.Strings.Fixed;

procedure Fibonacci is

   procedure Print_Usage is
   begin
      Put_Line
        ("Usage: please input the count of fibonacci numbers to output");
   end Print_Usage;

   function Img (N : Natural) return String
   is (Trim (Natural'Image (N), Ada.Strings.Left));

begin
   if Argument_Count /= 1 then
      Print_Usage;
      return;
   end if;

   declare
      N : Natural;
   begin
      begin
         N := Natural'Value (Argument (1));
      exception
         when Constraint_Error =>
            Print_Usage;
            return;
      end;

      if N = 0 then
         return;
      end if;

      declare
         A, B : Natural := 1;
         Next : Natural;
      begin
         for I in 1 .. N loop
            Put_Line (Img (I) & ": " & Img (A));

            Next := A + B;
            A := B;
            B := Next;
         end loop;
      end;
   end;

end Fibonacci;

Fibonacci in Ada 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.