Fibonacci series is a mathematical problem in which the third term is the sum of previous two terms. Fibonacci series is like 1 1 2 3 5 8 and it clear that the previous two terms make third term.
Source Code
import java.util.Scanner; public class Fibonacci{ public static void main(String[] args) { Scanner input = new Scanner (System.in); int num; long previous =1, next =0,sum; System.out.println(" Enter Your Number to Find its Fibonacci "); num = input.nextInt(); while (next<num/2) { System.out.print(previous+ " "); sum = previous+next; next = previous; previous = sum; } } }
0 comments:
Post a Comment