WAP IN JAVA TO PRINT THE FIBONACCI SERIES TILL 15 TERMS......!!!!!!!
Answers
Answered by
1
- public class Fibonacci.
- int n, a = 0, b = 0, c = 1;
- Scanner s = new Scanner(System.
- System. out. print("Enter value of n:");
- n = s. nextInt();
- System. out. print("Fibonacci Series:");
- for(int i = 1; i <= n; i++)
- a = b;
Answered by
45
Answer:
public class Fibonacci {
public static void main(String[] args) {
int n = 10, t1 = 0, t2 = 1;
System.out.print("First " + n + " terms: ");
for (int i = 1; i <= n; ++i)
{
System.out.print(t1 + " + ");
int sum = t1 + t2;
t1 = t2;
t2 = sum;
}
}
}
Similar questions