Created
July 1, 2026 13:48
-
-
Save webag/9a49ed1bb2cfebdf9b86e5dce5b06fb7 to your computer and use it in GitHub Desktop.
Фибонначи C
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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