Advertisement
Guest User

koolos

a guest
Nov 23rd, 2014
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1.  
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. int potegadwojki (int n)
  6. {
  7. if(n==0)
  8. {
  9. return 1;
  10. }
  11. else
  12. {
  13. return 2*(potegadwojki(n-1));
  14. }
  15. }
  16. int funkcja(int n)
  17. {
  18. if(n==0)
  19. {
  20. return 0;
  21. }
  22. if(n%2!=0)
  23. {
  24. return potegadwojki(n);
  25. }
  26. if(n%2==0)
  27. {
  28. return (funkcja(n-1) - funkcja(n-2));
  29. }
  30. }
  31.  
  32. int main()
  33. {
  34. int n;
  35. printf("Podaj n: ");
  36. scanf("%d",&n);
  37. printf("Wartosc funkcji dla %d wynosi: %d",n,funkcja(n));
  38. return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement