dComArk15/Aflevering5-x86-64/FibIter.java
Christoffer Müller Madsen e2e36f9f0d initial commit
2016-01-03 13:29:05 +01:00

36 lines
777 B
Java

/**
* Created by Casper on 08-12-2015.
*/
public class FibIter {
private static long fib_iter(long a) {
long r = 0;
long minus_one = 1;
long minus_two = 0;
if (a == 0) {
r = 0;
} else if (a == 1) {
r = 1;
} else {
for (long i = 2; i <= a; i++) {
r = minus_one + minus_two;
minus_two = minus_one;
minus_one = r;
}
}
return r;
}
public static void main(String[] args) {
long a = 0;
long r = 0;
a = Long.parseUnsignedLong(args[0]);
r = fib_iter(a);
System.out.println("fib(" + Long.toUnsignedString(a) + ") = " + r);
}
}