Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int fib_aux(int a, int b, int n) {
- if(n == 0) {
- return b;
- }
- fib_aux(b, a+b, n-1);
- }
- int fib(int n) {
- if(n == 1) {
- return 1;
- }
- if(n == 2) {
- return 1;
- }
- return fib_aux(1, 1, n-2);
- }
- int main() {
- int n;
- scanf("%d", &n);
- printf("%d", fib(n));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement