Menu

[r244]: / trunk / demos / Source / fibonacci_5.adb  Maximize  Restore  History

Download this file

70 lines (58 with data), 1.7 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
-- {{Ada/Sourceforge|fibonacci_5.adb}}
pragma License (Gpl);
pragma Ada_95;
with Ada.Text_IO;
with Ada.Command_Line;
procedure Fibonacci_5 is
type Integer_Type is delta 1.0 digits 18 range
0.0 .. 999_999_999_999_999_999.0;
package CL renames Ada.Command_Line;
package T_IO renames Ada.Text_IO;
package I_IO is new Ada.Text_IO.Decimal_IO (Integer_Type);
function Fib (N : Integer_Type) return Integer_Type;
Last : Positive;
Value : Integer_Type;
function Fib (N : Integer_Type) return Integer_Type is
U : Integer_Type := 0.0;
V : Integer_Type := 1.0;
begin
for I in 2 .. Integer (N) loop
Calculate_Next : declare
T : constant Integer_Type := U + V;
begin
U := V;
V := T;
end Calculate_Next;
end loop;
return V;
end Fib;
begin
I_IO.Get
(From => CL.Argument (1),
Item => Value,
Last => Last);
T_IO.Put ("The Fibonacci of ");
I_IO.Put
(Item => Value,
Fore => I_IO.Default_Fore,
Aft => I_IO.Default_Aft,
Exp => I_IO.Default_Exp);
T_IO.Put (" is ");
I_IO.Put
(Item => Fib (Value),
Fore => I_IO.Default_Fore,
Aft => I_IO.Default_Aft,
Exp => I_IO.Default_Exp);
return;
end Fibonacci_5;
----------------------------------------------------------------------------
-- $Author$
--
-- $Revision$
-- $Date$
--
-- $Id$
-- $HeadURL$
----------------------------------------------------------------------------
-- vim: textwidth=0 nowrap tabstop=8 shiftwidth=3 softtabstop=3 expandtab
-- vim: filetype=ada encoding=utf-8 fileformat=unix foldmethod=indent