Advertisement
RyBoL

Potęgowanie rekurencyjnie

Nov 30th, 2015
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.37 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int potega(int a, int b);
  4.  
  5. int main()
  6. {
  7.     int k, a, b;
  8.     k = potega(4, 3);
  9.     printf("%d", k);
  10.     getch();
  11.     return 0;
  12. }
  13.  
  14. int potega(int a, int b)
  15. {
  16.     if (b == 0) return 1;
  17.     else return a*potega(a, b-1);  
  18. }
  19.  
  20. //Napisz funkcje a do potegi b.
  21.  
  22. //pot(4, 3) = 4*pot(4, 2)
  23. //pot(4, 2) = 4*pot(4, 1)
  24. //pot(4, 1) = 4*pot(4, 0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement