Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class fibonacci_iterativo
- {
- public static void main( String[] args )
- {
- for( int i = 0; i < 10; i++ )
- System.out.println( fib(i) );
- }
- public static int fib( int n )
- {
- if( n == 0 )
- return 0;
- int a = 0, b = 1, c;
- for( int i = 1; i < n; i++ )
- {
- c = a;
- a = b;
- b = c + b;
- }
- return b;
- }
- }
Add Comment
Please, Sign In to add comment