44 lines
867 B
C#
44 lines
867 B
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
|
|
namespace Calculator
|
|
{
|
|
public static class MathHelper
|
|
{
|
|
|
|
#region Combinations
|
|
public static double Combinations(double n, double k)
|
|
{
|
|
k = Math.Min(k, n - k);
|
|
double a = 1, b = 1;
|
|
|
|
for (int i = 1; i <= k; i++)
|
|
{
|
|
a *= n - i + 1;
|
|
b *= i;
|
|
}
|
|
|
|
return a / b;
|
|
}
|
|
#endregion
|
|
|
|
public static double Arrangements(double n, double k)
|
|
{
|
|
double a = 1;
|
|
for (int i = 0; i < k; i++) a *= n - i;
|
|
|
|
return a;
|
|
}
|
|
|
|
public static double Factorial(double n)
|
|
{
|
|
double a = 1;
|
|
for (int i = 1; i <= n; i++) a *= i;
|
|
|
|
return a;
|
|
}
|
|
}
|
|
}
|