Advertisement
Guest User

Untitled

a guest
Dec 10th, 2018
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. using System;
  2.  
  3. namespace loto_probability
  4. {
  5. class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. int totalLottoBalls = Convert.ToInt32(Console.ReadLine());
  10. int ballsExtracted = Convert.ToInt32(Console.ReadLine());
  11. string category = Console.ReadLine();
  12. switch (category)
  13. {
  14. case "II":
  15. long denominator = Combinations(ballsExtracted,(ballsExtracted-1)) * Combinations(totalLottoBalls-ballsExtracted, (ballsExtracted-(ballsExtracted - 1)));
  16. long nominator= Combinations(totalLottoBalls, ballsExtracted);
  17. Console.Write(Probability(denominator, nominator));
  18. break;
  19. case "III":
  20. long denominator2 = Combinations(ballsExtracted, ballsExtracted - 2) * Combinations(totalLottoBalls - ballsExtracted, (ballsExtracted - (ballsExtracted - 2)));
  21. long nominator2 = Combinations(totalLottoBalls, ballsExtracted);
  22. Console.Write(Probability(denominator2, nominator2));
  23. break;
  24. default:
  25. Console.Write(Probability(1, Combinations(totalLottoBalls, ballsExtracted)));
  26. break;
  27.  
  28. }
  29.  
  30.  
  31. }
  32. static int Factorial(long number)
  33. {
  34. int factorial = 1;
  35. for(int i = 1; i <= number; i++)
  36. {
  37. factorial *= i;
  38. }
  39. return factorial;
  40. }
  41. static long Combinations(int n, int k)
  42. {
  43. long combinationsResult = Factorial(n) / (Factorial(k) * Factorial(n - k));
  44. return combinationsResult;
  45. }
  46.  
  47. static double Probability(long goodCases,long totalCases)
  48. {
  49.  
  50. double result=goodCases / totalCases;
  51. return Math.Round(result, 10);
  52. }
  53.  
  54.  
  55. }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement