Advertisement
lIlIlIlIIlI

Introduction_recursion

Sep 15th, 2019
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.33 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int function(int a){
  4.     if (a == 1) return 2;
  5.     else if (a == 2) return 4;
  6.     else if (a == 3) return 7;
  7.     else return 2 * function(a - 1) - function(a - 2) + 4 * function(a - 3);
  8. }
  9. int main(){
  10.     int number;
  11.     scanf("%d", &number);
  12.     int f = function(number);
  13.     printf("%d", f);
  14. }
  15.  
  16. /* f(x) = f(x-1) + f(x-2) */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement