Question9Max. score: 30.00Nth Fibonacci NumberInput format :An integerOutput format :An integerConstraints :1<=N<=1000000Sample input10Sample output89
Question
Question9Max. score: 30.00Nth Fibonacci NumberInput format :An integerOutput format :An integerConstraints :1<=N<=1000000Sample input10Sample output89
Solution
To find the Nth Fibonacci number, we can use a recursive approach.
- Read the input value of N, which represents the position of the Fibonacci number we want to find.
- Define a function called fibonacci that takes an integer parameter n.
- Inside the fibonacci function, check if n is either 0 or 1. If true, return n as the Fibonacci number.
- If n is greater than 1, recursively call the fibonacci function with n-1 and n-2 as parameters, and add the results together.
- Finally, call the fibonacci function with the input value of N and store the result in a variable called result.
- Print the value of result as the output.
Here is the code implementation in Python:
def fibonacci(n):
if n == 0 or n == 1:
return n
else:
return fibonacci(n-1) + fibonacci(n-2)
N = int(input("Enter the value of N: "))
result = fibonacci(N)
print("The", N, "th Fibonacci number is:", result)
For the given sample input of 10, the output will be 89.
Similar Questions
Question9Max. score: 30.00Nth Fibonacci NumberInput format :An integerOutput format :An integerConstraints :1<=N<=1000000Sample input10Sample output89Note:Your code must be able to print the sample output from the provided sample input. However, your code is run against multiple hidden test cases. Therefore, your code must pass these hidden test cases to solve the problem statement.LimitsTime Limit: 5.0 sec(s) for each input fileMemory Limit: 256 MBSource Limit: 1024 KBScoringScore is assigned if any testcase passesAllowed LanguagesC
Question67Max. score: 30.00Print Fibonacci numbers till nTake an input n and print Fibonacci numbers till n.Input FormatInteger input nConstraints0=n<=pow(10, 19)Output FormatFibonacci numbers till n.Sample input1Sample output0, 1, 1.ExplanationSample Input 01Sample Output 00, 1, 1.Sample Input 15Sample Output 10, 1, 1, 2, 3, 5.Sample Input 20Sample Output 20.Sample Input 34Sample Output 30, 1, 1, 2, 3.Sample Input 4100Sample Output 40, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89.Note:Your code must be able to print the sample output from the provided sample input. However, your code is run against multiple hidden test cases. Therefore, your code must pass these hidden test cases to solve the problem statement.LimitsTime Limit: 5.0 sec(s) for each input fileMemory Limit: 256 MBSource Limit: 1024 KBScoringScore is assigned if any testcase passes
Nth Fibonacci NumberMax. score: 30Input format :An integerOutput format :An integerConstraints :1<=N<=1000000SAMPLE INPUT 10SAMPLE OUTPUT 89Time Limit: 5.0 sec(s) for each input file.Memory Limit: 256 MBSource Limit: 1024 KBMarking Scheme: Score is assigned if any testcase passes.Allowed Languages: C
Question10Max. score: 40.00PatternInput format :two integersOutput format :Print patternconstraints :1<=N<=100Sample input5 4Sample outputX X X X X 0 0 X X 0 0 X X 0 0 X X X X XNote:Your code must be able to print the sample output from the provided sample input. However, your code is run against multiple hidden test cases. Therefore, your code must pass these hidden test cases to solve the problem statement.LimitsTime Limit: 5.0 sec(s) for each input fileMemory Limit: 256 MBSource Limit: 1024 KBScoringScore is assigned if any testcase passesAllowed LanguagesC
Everyone knows about fibonacci series: 1, 1, 2, 3, 5, 8, 13, 21, 34,..... . All you have to do is print the Nth fibonacci number.InputThe first line of input contains T - number of test cases. It is followed by T lines, each line containing a single integer - N.OutputFor each test case, print the Nth Fibonacci number, separated by new line. Since the number can be very large, print result % 1000000007.Constraints10 points1 <= T <= 10000 <= N <= 2030 points1 <= T <= 10000 <= N <= 10360 points1 <= T <= 10000 <= N <= 107100 points1 <= T <= 10000 <= N <= 1018ExampleInput7012710010000001000000000Output11221782204094534400663999999994
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.