Run ❯
Get your
own
website
×
Change Orientation
Change Theme, Dark/Light
Go to Spaces
Python
C
Java
def F(n): print('Computing F('+str(n)+')') if n <= 1: return n else: return F(n - 1) + F(n - 2) print('F(6) = ',F(6)) #Python
#include
int F(int n) { printf("Computing F(%d)\n", n); if (n <= 1) { return n; } else { return F(n - 1) + F(n - 2); } } int main() { printf("F(6) = %d\n", F(6)); return 0; } //C
public class Main { public static void main(String[] args) { System.out.println("F(6) = " + F(6)); } public static int F(int n) { System.out.println("Computing F(" + n + ")"); if (n <= 1) { return n; } else { return F(n - 1) + F(n - 2); } } } //Java
Python result:
C result:
Java result:
Computing F(6)
Computing F(5)
Computing F(4)
Computing F(3)
Computing F(2)
Computing F(1)
Computing F(0)
Computing F(1)
Computing F(2)
Computing F(1)
Computing F(0)
Computing F(3)
Computing F(2)
Computing F(1)
Computing F(0)
Computing F(1)
Computing F(4)
Computing F(3)
Computing F(2)
Computing F(1)
Computing F(0)
Computing F(1)
Computing F(2)
Computing F(1)
Computing F(0)
F(6) = 8
Computing F(6)
Computing F(5)
Computing F(4)
Computing F(3)
Computing F(2)
Computing F(1)
Computing F(0)
Computing F(1)
Computing F(2)
Computing F(1)
Computing F(0)
Computing F(3)
Computing F(2)
Computing F(1)
Computing F(0)
Computing F(1)
Computing F(4)
Computing F(3)
Computing F(2)
Computing F(1)
Computing F(0)
Computing F(1)
Computing F(2)
Computing F(1)
Computing F(0)
F(6) = 8
Computing F(6)
Computing F(5)
Computing F(4)
Computing F(3)
Computing F(2)
Computing F(1)
Computing F(0)
Computing F(1)
Computing F(2)
Computing F(1)
Computing F(0)
Computing F(3)
Computing F(2)
Computing F(1)
Computing F(0)
Computing F(1)
Computing F(4)
Computing F(3)
Computing F(2)
Computing F(1)
Computing F(0)
Computing F(1)
Computing F(2)
Computing F(1)
Computing F(0)
F(6) = 8