Advertisement
Guest User

kolos

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