Computer Science, asked by pallavi1967, 2 months ago

Write a program in java to print first 50 terms of Fibonacci series excluding 34th and 43rd term.

Answers

Answered by harshit4verma2005
0

Answer: The Fibonacci series is a series where the next term is the sum of the previous two terms. The first two terms of the Fibonacci sequence are 0 followed by 1.

The Fibonacci sequence: 0, 1, 1, 2, 3, 5, 8, 13, 21, ...

Example 1: Display Fibonacci series using for loop

public class Fibonacci {

   public static void main(String[] args) {

       int n = 10, t1 = 0, t2 = 1;

       System.out.print("First " + n + " terms: ");

       for (int i = 1; i <= n; ++i)

       {

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

           int sum = t1 + t2;

           t1 = t2;

           t2 = sum;

       }

   }

}

Output

0 + 1 + 1 + 2 + 3 + 5 + 8 + 13 + 21 + 34 +  

In the above program, first (t1) and second (t2) terms are initialized to the first two terms of the Fibonacci series 0 and 1 respectively.

Then, for loop iterates to n (number of terms) displaying the sum of the previous two terms stored in variable t1.

Similar questions