Guest User

Untitled

a guest
Feb 23rd, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.33 KB | None | 0 0
  1. public class fibonacci_iterativo
  2. {
  3. public static void main( String[] args )
  4. {
  5. for( int i = 0; i < 10; i++ )
  6. System.out.println( fib(i) );
  7. }
  8.  
  9. public static int fib( int n )
  10. {
  11. if( n == 0 )
  12. return 0;
  13.  
  14. int a = 0, b = 1, c;
  15.  
  16. for( int i = 1; i < n; i++ )
  17. {
  18. c = a;
  19. a = b;
  20. b = c + b;
  21. }
  22.  
  23. return b;
  24. }
  25. }
Add Comment
Please, Sign In to add comment