Computer Science, asked by deeyagurung420, 4 months ago

Make a class FibSeries to generate Fibonacci series: 0, 1, 1, 2, 3, 5, 8, 13, 21, ........ (The
Fibonacci series is generated by adding two previous terms by taking 0, 1 as starting terms.
Date :
QUESTION 1:
Example : the starting values are 0, 1 then if add (0+1)=1 (this is third term), then ada
(1+1) = 2 (this is 4th term and so on).
Private variables of class are first, second, third (integer types).
Public functions of class are :
FibSeries( )- to store O to first and 1 to second (as two starting terms).
(ii) void PrintSeries()- to print Fibonacci series up to 30 terms using while loop.
Write a program to print the Fibonacci series by calling suitable functions.
Answer:​

Answers

Answered by shilpa85475
2

Fibonacci series in the number system are nothing but the list if numbers in which the 3rd number is the addition of the 1st two numbers. For eg, 0,1,2

So here, 2 is the addition of 0 and 1. Hence the series of the number will be:

0, 1, 1, 2, 3, 5, 8, 13, 21

Explanation:

public class Fibo

{  

  public static void main(String args[])  

  {    

   int first=0;

int second=1;

int third;

int i,count=10;    

   System.out.print(first+" "+second);  

       

   for(i=2;i<count;++i)  

   {    

    third=first+second;    

    System.out.print(" "+third);    

    first=second;    

    second=third;    

   }    

     

  }

}

Similar questions