Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite76fa83

Browse files
authored
Create algo-nthfibonacci
1 parent6b36fd8 commite76fa83

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

‎algo-nthfibonacci‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
def getNthFib(n):
2+
x = 0
3+
y = 1
4+
fib_num = 0
5+
if n == 2:
6+
return 1
7+
elif n == 1:
8+
return 0
9+
else:
10+
for i in range(2, n):
11+
fib_num = x + y
12+
x, y = y, fib_num
13+
return fib_num
14+
15+
16+
def getNthFib(n):
17+
x = 0
18+
y = 1
19+
fib_num = 0
20+
if n == 2:
21+
return 1
22+
elif n == 1:
23+
return 0
24+
else:
25+
for i in range(2, n):
26+
fib_num = x + y
27+
x, y = y, fib_num
28+
return fib_num

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp