Advertisement
Holek

Untitled

Feb 9th, 2017
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.52 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. /*Zaimplementuj zdefiniowaną poniżej funkcję rekurencyjną:
  5. A(p, q) =
  6.  
  7. 2q dla p = 0,
  8. 0 dla q = 0 i p ­ 1,
  9. 2 dla p ­ 1 i q = 1,
  10. A(p − 1, A(p, q − 1)) dla p ­ 1 i q ­ 2.
  11.  
  12. */
  13. int rekurencja(int p,int q){
  14.     if(p == 0)
  15.         return 2*q;
  16.     if(q==0 && p>=1)
  17.         return 0;
  18.     if(p>=1 && q== 1)
  19.         return 2;
  20.     if(p>=1 && q>=2)
  21.         return rekurencja(p-1,rekurencja(p,q-1));
  22. }
  23. int main(){
  24.  
  25.  
  26.     printf("%i",rekurencja(3,3));
  27.     return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement