Results 1 to 2 of 2
Thread: Iterative Algorithms
- 05-06-2008, 06:02 AM #1
Iterative Algorithms
This is a sample of the iterative approach to Fibonacci numbers.
the number this will work for is 190Java Code:/** * @(#)FibonacciNumbers.java * * * @author * @version 1.00 2008/5/5 */ public class FibonacciNumbers { public FibonacciNumbers(long n) { System.out.println("Your number is: " + this.findNumbers(n)); } private long findNumbers(long n) { long temp1 = 1; long temp2 = 0; long fibonacciNumber = 0; for (long i = 2; i <= n; i++) { fibonacciNumber = temp1 + temp2; temp2 = temp1; temp1 = fibonacciNumber; } return fibonacciNumber; } public static void main(String[] args) { FibonacciNumbers fibNum = new FibonacciNumbers(190); } }My IP address is 127.0.0.1
- 07-05-2008, 06:29 AM #2
Hm, i think it is wrong. If n=190 the fibNum is more than 18 digit, while long int only 18 digit...
n = 190 , fibnum is more than 19 digit while long int has only 18 digit, what is the fibonacci of 100? The answer is 354224848179261915075 and it's more than 19 digit...
I think it is wrong. If(n==190) the answer is more than 19 digit while long only 19 digit...
CMIIW..Last edited by CaptainMorgan; 08-01-2008 at 07:18 AM.
Similar Threads
-
Algorithms and data from a File Problem
By BHCluster in forum Advanced JavaReplies: 0Last Post: 04-18-2008, 04:38 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks