첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170

▶ 순열 구하기 예제

using System;

long permutation = GetPermutation(3, 2);

Console.WriteLine(combination);

 

728x90

 

▶ 순열 구하기

#region 순열 구하기 - GetPermutation(totalCount, extractionCount)

/// <summary>
/// 순열 구하기
/// </summary>
/// <param name="totalCount">전체 수</param>
/// <param name="extractionCount">추출 수</param>
/// <returns>순열</returns>
public long GetPermutation(int totalCount, int extractionCount)
{
    return GetFactorialDivision(totalCount, totalCount - extractionCount);
}

#endregion

#region 팩토리얼 분할 구하기 - GetFactorialDivision(topFactorial, divisorFactorial)

/// <summary>
/// 팩토리얼 분할 구하기
/// </summary>
/// <param name="topFactorial">상위 팩토리얼</param>
/// <param name="divisorFactorial">제수 팩토리얼</param>
/// <returns>팩토리얼 분할</returns>
private long GetFactorialDivision(int topFactorial, int divisorFactorial)
{
    long result = 1;

    for(int i = topFactorial; i > divisorFactorial; i--)
    {
        result *= i;
    }

    return result;
}

#endregion
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요