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