Advertisement
AnindyaBiswas

Fibo

Apr 27th, 2022
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.41 KB | None | 0 0
  1. import java.util.*;
  2. public class Fibo {
  3.     public static void main(String args[])
  4.     {
  5.         int a = -1, b = 1,c;
  6.         Scanner sc = new Scanner(System.in);
  7.         System.out.print("Enter a no : ");
  8.         int n = sc.nextInt();
  9.         for(int i = 1; i<= n; i++)
  10.         {
  11.             c = a + b;
  12.             System.out.print(c + " ");
  13.             a = b;
  14.             b = c;
  15.         }
  16.     }
  17.    
  18. }
  19.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement