Array-promo

Question

Program to print Fibonacci series

				
					ENTER THE NUMBER OF TERM :
10
FIBONACCI SERIES :
0 1 1 2 3 5 8 13 21 34 
				
			

Share code with your friends

Share on whatsapp
Share on facebook
Share on twitter
Share on telegram

Code

				
					import java.util.Scanner;
public class fibonacciSeries
{  
    public static void main(String[] args)
    {  
        

        int n=0,i=0,a=0,b=1,c=0;
        Scanner sc = new Scanner(System.in);    

        System.out.println("Enter size of series");   
        n = sc.nextInt(); 
        
        System.out.print(a+" "+b);
        for(i=2;i< n;i++)
        {
            c=a+b;
            System.out.print(" "+c);
            a=b;
            b=c;
        }
        
    }

   
}


				
			

Coding Store

Leave a Reply

Your email address will not be published. Required fields are marked *