Fibnacci series (rec)

class Fib{
    static int fib(int a)
    {
        if (a==1||a==2)
            return 1;
        else{
            int n=fib(a-1)+fib(a-2);
            return n;
        }
        
    }
    public static void main(String ar[])throws Exception {
        int a=10,i;
        for(i=1;i<=a;i++)
        {
            System.out.printf("%5d",fib(i));
        }
    }
}

No comments:

Popular Posts