Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static int fibonacci(int n){
- int Un = 0;
- int Un1 = 1;
- int Un2 = 1;
- int temp = 0;
- for(int i = 0; i <= n; i++) {
- if(i == 0) {
- temp = 0;
- }
- if(i == 1) {
- temp = 1;
- }
- else {
- Un2 = Un1;
- Un1 = Un;
- Un = Un2 + Un1;
- temp = Un;
- }
- }
- return temp;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement