fork download
  1. Imports System
  2. Public Class Pascalls_Triangle
  3. Public Shared Sub Main()
  4. 'Returns the number at the location inside pascalls triangle
  5. console.writeline(Pascalls_Return_n_Of_k(4,2))
  6. End Sub
  7.  
  8. Public Shared Function Return_Factorial_Of_n(Byval n as Integer)
  9. 'n! = n * (n-1)... * 3 * 2 * 1
  10. dim nFactorial as uint64 = 1
  11. for i as uint64 = n to 1 step -1
  12. nFactorial *= i
  13. Next
  14. Return nFactorial
  15. End Function
  16.  
  17. Public Shared Function Pascalls_Return_n_Of_k(Byval n as int64, Byval k as int64)
  18. '(n choose k) = n!/k!*(n - k)!
  19. 'Example: n = Row, k = Term
  20. ' 1 - Row(0)
  21. ' 1 1 - Row(1)
  22. ' 1 2 1 - Row(2)
  23. ' 1 3 3 1 - Row(3)
  24. ' 1 4 6 4 1 - Row(4)
  25. '
  26. ' ' ' ' ' '
  27. ' ' ' ' ' Term(4)
  28. ' ' ' ' Term(3)
  29. ' ' ' Term(2)
  30. ' ' Term(1)
  31. ' Term(0)
  32. Return (Return_Factorial_Of_n(n) / (Return_Factorial_Of_n(k) * Return_Factorial_Of_n(n-k)))
  33. End Function
  34. end class
Runtime error #stdin #stdout 0.08s 36328KB
stdin
Standard input is empty
stdout
Standard output is empty