1. Using JavaScript
What is the nth number of Fibonacci sequences?
// Requirement: Encapsulates a function to find the nth term of the Fibonacci sequence
Fibonacci sequence
var n=parseint (Prompt ("Enter the number of Fibonacci sequences you want to Know");
document.write (f (n));
function f (n) {
if (n>=3) {
var a=1;
var b=1;
for (Var i=3;i<=n;i++) {
var temp=b;
B=a+b;
A=temp;
}
return b;
}
else if (n<=2) {
Return 1
}
}
2. Using the Python method
whileTrue:#Implement the function of finding the Fibonacci sequence to n items multiple timesN=int (Input ("Please enter an integer:")) if0<n<=2:#1th, 2 digits is 1 Print("Fibonacci Sequence No."N"items are: 1") Print("To exit, press: 0")#prompts the user to press 0 to exit elifN>=3:#N At the beginning of the 3rd bitA = 1b= 1F=0 I=3 while3<=i<=n:f= A +B a=b b=F i+=1Print("Fibonacci Sequence No."N"items are:", B)Print("To exit, press: 0") elifN==0:#Press 0 to exit at any timeExit ()
Fibonacci sequence (implemented in JavaScript and Python)