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?
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;
}
}
}
+ 2
Negative Fibonacci series is nothing but drive from equation
F-n = -(-1)nFn
Where Fn is Fibonacci number in positive.
Source from Wikipedia