Skip to content

Instantly share code, notes, and snippets.

@webag
Created July 1, 2026 13:48
Show Gist options
  • Select an option

  • Save webag/9a49ed1bb2cfebdf9b86e5dce5b06fb7 to your computer and use it in GitHub Desktop.

Select an option

Save webag/9a49ed1bb2cfebdf9b86e5dce5b06fb7 to your computer and use it in GitHub Desktop.
Фибонначи C
#include <stdio.h>
long long fibonacci(int n);
int main() {
int a;
char c;
if (scanf("%d%c", &a, &c) != 2 || c != '\n' || a <=0) {
printf("n/a\n");
} else {
printf("%d\n", fibonacci(a));
}
return 0;
}
long long fibonacci(int n) {
// Base cases
if (n == 0) {
return 0;
}
if (n == 1) {
return 1;
}
// Recursive case
return fibonacci(n - 1) + fibonacci(n - 2);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment