Advertisement
18126

Day3(ex5)

Jul 8th, 2021
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.50 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4.  
  5. int Fibo(int n, int a, int b) {
  6.     if(n == 1) {
  7.         return a+b;
  8.     }
  9.     if(a == 0) {
  10.         a = 1;
  11.         n = n - 1;
  12.         return Fibo(n, a, b);
  13.     }
  14.     n = n - 1;
  15.     int temp = a+b;
  16.     b = a;
  17.     a = temp;
  18.     return Fibo(n, a, b);
  19. }
  20.  
  21. int main() {
  22.     int n, prev1 = 0, prev2 = 1;
  23.     printf("Enter n: ");
  24.     scanf("%d", &n);
  25.     printf("Fibo(%d) = %d", n, Fibo(n, prev1, prev2));
  26.     return EXIT_SUCCESS;
  27. }
  28.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement