Write a program to generate Fibonacci series up to the limit entered by the user.

 Write a program to generate Fibonacci series upto the limit entered by the user.



package lab0;

import java.util.Scanner;

public class Ques_4 {

public static void main(String[] args) {

int n, t1 = 0, t2 = 1;

Scanner sc = new Scanner(System.in);

System.out.print("Enter limit upto which you want to print fibinacci series:");

n = sc.nextInt();

sc.close();

System.out.print("Upto " + n + ": ");

while (t1 <= n) {

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

int sum = t1 + t2;

t1 = t2;

t2 = sum;

}

}

}

OUTPUT



Post a Comment

0 Comments