+ 2

Write a program to print the sum of Fibonacci numbers.

Write a program in Java to print the sum of Fibonacci numbers where S = 0 + 1 + 1 + 2 + 3 + 5 + 8 + 13 +... (Upto N terms) Accept N from the user. The program should be modified such that it can output N = 1 or N = 2. I gave a reference code, please check whether it is correct or not.

2nd Nov 2019, 9:32 AM
GiantJupiter
GiantJupiter - avatar
2 Réponses
+ 1
Logic : int f=0; int s = 1; Int next; Int range = sc.nextInt(system.in) For(int i=0;i<range;i++) { System.out.print(f + " ") Next = f+s F= s S= next } System.out.println("sum of fabonacci"+next);
2nd Nov 2019, 9:39 AM
Chirag Kumar
Chirag Kumar - avatar
0
Please write it in the form of a program and it was "n", where "n" means number, not next
2nd Nov 2019, 4:36 PM
GiantJupiter
GiantJupiter - avatar