File: fibonacci.e

package info (click to toggle)
libjlatexmath-java 1.0.7-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 5,268 kB
  • sloc: xml: 23,113; java: 13,399; makefile: 37; cpp: 30; sh: 10
file content (64 lines) | stat: -rw-r--r-- 1,521 bytes parent folder | download | duplicates (2)
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
indexing
	 description :
	 "{
	 Retourne l'élément de rang `n' de la suite de fibonacci (Version itérative)
	 La suite de Fibonacci est définie par :
	 <xi:include 
	     xmlns:xi="http://www.w3.org/2001/XInclude"
		  href="&equations;eq-2dim.xml"
		  parse="xml"/>
	 }"
	auteurs       : "Christophe HARO"
	copyright_auteur  : "Auteur  : (c) Christophe HARO, 2010"
	licenses_url  : "http://www.gnu.org/licences/gpl-3-0.html"
	licence       : "GPL"
	projet        : "JLATEXMATH"
	dossier       : "${DOCBOOK}/jlatexmath/"
	fichier       : "fibo.e"
	date          : "$Date: 2010-04-16 09:28:46 +0200 (Ven 16 avr 2010) $"
	revision      : "$Revision: 13 $"
	url           : "$HeadURL: svn://localhost/jlatexmath/programmes/fibonacci.e $"
	modifications : "$Author: haro $"

...

feature
	
	 fibonacci(n : INTEGER) : INTEGER is
				-- L'élément de rang `n'
	 
		  require
				n > 0
			
		  local
				     i : INTEGER -- Le rang du dernier élément calculé
				f1, f2 : INTEGER -- Les deux éléments qui le précèdent
		  do
				from
					     f1 := 1 -- fibonacci(i-1) : terme de rang 1
					 Result := 1 -- fibonacci(i)   : terme de rang 2
					      i := 2 -- Rang du dernier terme calculé
				
				invariant
					 Result = fibonacci(i)
					    f1  = fibonacci(i-1)
				variant
					 n - i
				
				until
					 i >= n
					 
				loop
					 f2 := f1
					 f1 := Result
					 Result := f1 + f2
					 i := i + 1
				end

		  ensure
				--"{ Result est l'élément de rang `n' de la suite }"
				
		  end
...