WAP to find the Fibonacci Series of a given number
import java.util.*;
class T12 {
public static void main(String[] args) {
int n, n1 = 0, n2 = 1, n3, i;
Scanner sc = new Scanner(System.in);
System.out.print("How many terms you want in series : ");
n = sc.nextInt();
System.out.print(n1 + " " + n2 + " ");
for (i = 1; i <= n - 2; i++) {
n3 = n1 + n2;
System.out.print(n3 + " ");
n1 = n2;
n2 = n3;
}
}
}
Copy Code