fork download
  1. #include <iostream>
  2. #include <iomanip>
  3.  
  4. double compute_p(double n, double c) {
  5. double ndc = n - c, p = 1;
  6. for(int i = 0; i < 4 ; ++i, --ndc, --n) { p *= ndc/n; }
  7. return 1 - p;
  8. }
  9.  
  10. int main() {
  11. std::cout << std::setprecision(3);
  12. constexpr int nmin = 45, nmax = 53;
  13. constexpr int cmin = 15, cmax = 30;
  14. std::cout << "c\\n\t";
  15. for(int n = nmin ; n <= nmax ; ++n)
  16. std::cout << " " << std::setw(4) << n;
  17. std::cout << '\n';
  18. for(int c = cmin ; c <= cmax ; ++c) {
  19. std::cout << c << '\t';
  20. for(int n = nmin; n <= nmax ; ++n) {
  21. std::cout << " " << std::setw(4) << compute_p(n, c)*100 << '%';
  22. }
  23. std::cout << '\n';
  24. }
  25. }
Success #stdin #stdout 0s 4532KB
stdin
50 25
stdout
c\n	     45     46     47     48     49     50     51     52     53
15	  81.6%  80.7%  79.8%    79%  78.1%  77.3%  76.4%  75.6%  74.8%
16	  84.1%  83.2%  82.4%  81.5%  80.7%  79.9%    79%  78.2%  77.4%
17	  86.3%  85.4%  84.6%  83.8%    83%  82.2%  81.4%  80.7%  79.9%
18	  88.2%  87.5%  86.7%  85.9%  85.1%  84.4%  83.6%  82.9%  82.1%
19	    90%  89.2%  88.5%  87.8%  87.1%  86.3%  85.6%  84.9%  84.2%
20	  91.5%  90.8%  90.2%  89.5%  88.8%  88.1%  87.4%  86.7%    86%
21	  92.9%  92.2%  91.6%    91%  90.3%  89.7%    89%  88.4%  87.7%
22	  94.1%  93.5%  92.9%  92.3%  91.7%  91.1%  90.5%  89.9%  89.3%
23	  95.1%  94.6%    94%  93.5%  92.9%  92.4%  91.8%  91.2%  90.6%
24	    96%  95.5%    95%  94.5%    94%  93.5%    93%  92.4%  91.9%
25	  96.7%  96.3%  95.9%  95.4%    95%  94.5%    94%  93.5%    93%
26	  97.4%    97%  96.6%  96.2%  95.8%  95.4%  94.9%  94.5%    94%
27	  97.9%  97.6%  97.3%  96.9%  96.5%  96.2%  95.7%  95.3%  94.9%
28	  98.4%  98.1%  97.8%  97.5%  97.2%  96.8%  96.5%  96.1%  95.7%
29	  98.8%  98.5%  98.3%    98%  97.7%  97.4%  97.1%  96.7%  96.4%
30	  99.1%  98.9%  98.7%  98.4%  98.2%  97.9%  97.6%  97.3%    97%