Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
359 B
0
Indexable
Never
#include <stdio.h>

int fib(int n) {
  if (n <= 1) {
    return n;
  } else {
    return fib(n - 1) + fib(n - 2);
  }
}

int main() {
  int n;
  printf("Enter a number: ");
  scanf("%d", &n);
  printf("The first %d Fibonacci numbers are: ", n);
  for (int i = 0; i < n; i++) {
    printf("%d ", fib(i));
  }
  printf("\n");
  return 0;
}
Leave a Comment