Run ❯
Get your
own
website
×
Change Orientation
Change Theme, Dark/Light
Go to Spaces
Python
C
Java
print(0) print(1) count = 2 def fibonacci(prev1, prev2): global count if count <= 19: newFibo = prev1 + prev2 print(newFibo) prev2 = prev1 prev1 = newFibo count += 1 fibonacci(prev1, prev2) else: return fibonacci(1,0) #Python
#include
int count = 2; void fibonacci(int prev1, int prev2) { if (count <= 19) { int newFibo = prev1 + prev2; printf("%d\n", newFibo); prev2 = prev1; prev1 = newFibo; count += 1; fibonacci(prev1, prev2); } else { return; } } int main() { printf("0\n"); printf("1\n"); fibonacci(1, 0); return 0; } //C
public class Main { static int count = 2; public static void fibonacci(int prev1, int prev2) { if (count <= 19) { int newFibo = prev1 + prev2; System.out.println(newFibo); prev2 = prev1; prev1 = newFibo; count += 1; fibonacci(prev1, prev2); } else { return; } } public static void main(String[] args) { System.out.println(0); System.out.println(1); fibonacci(1, 0); } } //Java
Python result:
C result:
Java result:
0
1
1
2
3
5
8
13
21
34
55
89
144
233
377
610
987
1597
2584
4181
0
1
1
2
3
5
8
13
21
34
55
89
144
233
377
610
987
1597
2584
4181
0
1
1
2
3
5
8
13
21
34
55
89
144
233
377
610
987
1597
2584
4181