fork download
  1. #include <stdio.h>
  2.  
  3. // Function to print Fibonacci series using recursion
  4. void fib(int a, int b, int n) {
  5. if (n > 0) {
  6. printf("%d ", a);
  7. fib(b, a + b, n - 1); // Recursive call
  8. }
  9. }
  10.  
  11. int main() {
  12. int N = 10; // Number of terms
  13. printf("Fibonacci Series: ");
  14. fib(0, 1, N); // Starting with 0 and 1
  15. return 0;
  16. }
Success #stdin #stdout 0.02s 25900KB
stdin
1
2
10
42
11
stdout
#include <stdio.h>

// Function to print Fibonacci series using recursion
void fib(int a, int b, int n) {
    if (n > 0) {
        printf("%d ", a);
        fib(b, a + b, n - 1); // Recursive call
    }
}

int main() {
    int N = 10; // Number of terms
    printf("Fibonacci Series: ");
    fib(0, 1, N); // Starting with 0 and 1
    return 0;
}