Write a method to calculate the nth Fibonacci number for n<1000. The nth Fibonacci number is the sum of the two previous numbers. The first two numbers are both 1. Return 0 for n<=0 or n>1000. E.g.,Fibonacci(1) returns 1Fibonacci(2) returns 1Fibonacci(3) returns 2Fibonacci(4) returns 3Fibonacci(5) returns 5Fibonacci(6) returns 8Fibonacci(N) returns Fibonacci(N-1) + Fibonacci(N-2)First complete the simple method below. Then describe how you could make it more efficient. public int Fibonacci(int N) { if (N <= 0 || N > 1000)What I have tried:I have no clue how to do this Write a method to calculate the nth Fibonacci number for n<1000. The nth Fibonacci number is the sum of the two previous numbers. The first two numbers are both 1. Return 0 for n<=0 or n>1000. E.g.,Fibonacci(1) returns 1Fibonacci(2) returns 1Fibonacci(3) returns 2Fibonacci(4) returns 3Fibonacci(5) returns 5Fibonacci(6) returns 8Fibonacci(N) returns Fibonacci(N-1) + Fibonacci(N-2)First complete the simple method below. Then describe how you could make it more efficient. public int Fibonacci(int N) { if (N <= 0 || N > 1000) 解决方案 这篇关于Csalculzate第n个斐波那契数n<> 1000的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-19 05:14