Skip to main content

Posts

Showing posts with the label program

java program for finding the nth fibonacci number using recursion

 java program for finding the nth fibonacci number using recursion Code:: import java.util.*; import java.lang.*; import java.io.*; class Test{ public static int fib(int n){ if(n<=1){ return n; } return fib(n-1) + fib(n-2); } public static void main(String[] args){ System.out.println(fib(7)); } }  o/p::  13 0 -> 0th fib num 1-> 1st fib num 1 -> 2nd fib num 2 -> 3rd fib num 3....>4th 5...->5th 8->6th 13-> 7th