PYTHON   22

binomial2

Guest on 13th August 2022 07:55:35 AM

  1. m = int(input("Digite m: "))
  2. n = int(input("Digite n: "))
  3.  
  4. # calcule m!
  5. k = m
  6.  
  7. k_fat = 1
  8. i = 2
  9. while i <= k:
  10.     k_fat *= i
  11.     i += 1
  12.  
  13. m_fat = k_fat
  14.  
  15.  
  16. # calcule n!
  17. k = n
  18.  
  19. k_fat = 1
  20. i = 2
  21. while i <= k:
  22.     k_fat *= i
  23.     i += 1
  24.  
  25. n_fat = k_fat
  26.  
  27. # calcule m-n!
  28. k = m-n
  29.  
  30. k_fat = 1
  31. i = 2
  32. while i <= k:
  33.     k_fat *= i
  34.     i += 1
  35.  
  36. mn_fat = k_fat
  37.  
  38. binomial = m_fat//(n_fat * mn_fat)
  39.  
  40. print(f"binomial({m}, {n}) = {binomial}")

Raw Paste


Login or Register to edit or fork this paste. It's free.