1.

Write about fabonacci series with example

Answer»

ci series Fibonacci series proceeds by adding up the previous two terms . Suppose the FIRST 2 terms are 4 and 5 .Then next term will be 4 + 5 = 9Then the next term will be 9 + 5 = 144 , 5 , 9 , 14 .................. is an example of the fibonacci series .More EXAMPLES :6 , 8 ... ?6 + 8 = 148 + 14 = 2214 + 22 = 366 , 8 , 14 , 22 , 36 ..................... is another example .Properties of the series.You can subtract any term from the next term to get the previous term .For example :1 , 2 , 3 , 5 , 8 ............Subtract 5 from 8 to get the previous term .8 - 5 = 3Code in Java for the series :import java.util.*;class fibonacci {public static void main(String args[]){Scanner sc=new Scanner(System.in);System.out.println("Enter a limit");int n=sc.nextInt();int a=0;int b=1;System.out.println(a);System.out.println(b);for(int i=3;i<=n;i++){int c=a+b;System.out.println(c);a=b;b=c;}}}/*The LOGIC is just swapping the previous variable to print the *pattern.*/



Discussion

No Comment Found