Fibbonachi numbers

 package loops;

import java.util.Scanner;

public class FibonacciNumbers {


public static void main(String[] args) {

/* Fibonacci numbers mai last ke 2 number ka sum hota hai agla number

jese

0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181.....

*/

Scanner sc = new Scanner(System.in);

int n = sc.nextInt();

int a = 0;

int b = 1;

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

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

for(int i = 0; i<n-2; i++){

int c = a+b;

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

a = b;

b = c;

}

 

}


}

Comments

Popular posts from this blog

Simple Intrest

Else if

Sum of Digits