DilyaraL

РЕКУРСИЯ

May 2nd, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <math.h>
  4. using namespace std;
  5.  
  6. double power(double x, int n)
  7. {
  8. if (n == 0)
  9. return 1;
  10. else
  11. {
  12. if (n < 0)
  13. {
  14. n = abs(n);
  15. x = 1.0 / x;
  16. }
  17. return x*power(x,n-1);
  18. }
  19. }
  20.  
  21. int binom(int m, int n)
  22. {
  23. if (m == n || m == 0)
  24. return 1;
  25. else
  26. return binom(m , n-1) + binom(m - 1, n - 1);
  27. }
  28.  
  29. int main()
  30. {
  31. double x=0.5;
  32. int n =-3;
  33. //cout << power(x, n) << endl;
  34. cout << binom(3,5) << endl;
  35. system("pause");
  36. return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment