Advertisement
Guest User

binBin

a guest
Oct 4th, 2015
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. // bin&Bin Calculator
  2. // Jean-Marc Saad
  3. #include <iostream>
  4. #include <cmath>
  5. #include <string>
  6. using namespace std;
  7. int factorial(int n);
  8. double Combination(int,int);
  9. double bin(int,int,double);
  10. double Bin(int,int,double);
  11. int main()
  12. {
  13. int x,y;
  14. double z;
  15. int io;
  16. cout << " 0 for bin, 1 for Bin " << endl;
  17. cin >> io;
  18. if (io == 0)
  19. cout << " b(a,b,c) " << endl;
  20. else
  21. cout << " B(a,b,c) " << endl;
  22. cout << "a = ";
  23. cin >> x;
  24. cout << "b = ";
  25. cin >> y;
  26. cout << "c = ";
  27. cin >> z;
  28. if (io == 0)
  29. cout << bin(x,y,z);
  30. else
  31. cout << Bin(x,y,z);
  32.  
  33. return 0;
  34. }
  35. int factorial(int n)
  36. {
  37. if (n == 0)
  38. return 1;
  39. return n * factorial(n - 1);
  40. }
  41. double Combination(int a, int b)
  42. {
  43. return (factorial(a))/((factorial(b))*(factorial(a-b)));
  44. }
  45. double bin(int a,int b,double x)
  46. {
  47. return (Combination(b,a))*pow(x,a)*pow(1-x,b-a);
  48. }
  49. double Bin(int a, int b, double x)
  50. {
  51. double sum = 0;
  52. for (int i=0;i<=a;i++)
  53. {
  54. sum += bin(i,b,x);
  55. }
  56. return sum;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement