Search This Blog

Saturday, 1 February 2014

fibacnocci series in java

/* program to generate a series called fibanocci series  */


class Fibanocci
{
    public static void main(String[] args)
    {
        int a=0,b=1,c,i,n;
        Scanner sc=new Scanner(System.in);
        System.out.println("Enter the limit of the series : ");
        n=sc.nextInt();
        for(i=1;i<=n;i++)
        {
            c=a+b;
            System.out.print(c+" ");
            a=b;
            b=c;
        }
    }
}

Output


Enter the limit of the series : 
8
1 2 3 5 8 13 21 34 

No comments:

Popular Posts