0

How to create a negative fibonacci series?

is it the Same Code like a positive fibonacci series Just with minus-sign in Front of the variables or what would All Change?

17th Nov 2016, 2:23 PM
thejokahr
thejokahr - avatar
2 Respostas
+ 3
Here is your code for negative Fibonacci series import java.util.*; public class Program { public static void main(String[] args) { int n=0; Scanner sc = new Scanner(System.in); System.out.println("Please entered number"); n=sc.nextInt(); System.out.println("You have entered "+n); int f1, f2=0, f3=1; for(int i=1;i<=n;i++){ System.out.print(" "+-(int)Math.pow(-1,i)*f3+" "); f1 = f2; f2 = f3; f3 = f1 + f2; } } }
17th Nov 2016, 3:06 PM
Aditya kumar pandey
Aditya kumar pandey - avatar
+ 2
Negative Fibonacci series is nothing but drive from equation F-n = -(-1)nFn Where Fn is Fibonacci number in positive. Source from Wikipedia
17th Nov 2016, 3:08 PM
Aditya kumar pandey
Aditya kumar pandey - avatar