TechLivoasis
Simplifying Tech, Elevating Life
Search This Blog
2026/08/11
Javascript:Find nth fibonacci number
Find
nth
fibonacci
number.
code:
function
fibonacci
(
n
){
if(n
==1
||
n
=
=2
){
return
1
}else{
return
fibonacci
(
n-1
)
+
fibonacci
(
n-2
)
}
}
let
num
=
fibonacci
(
5
)
console.log(num
)
output:
5
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment