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

▶ 최대 공약수 구하기 예제

using System;

uint gcm = GetGreatestCommonDivisor(32, 18);

Console.WriteLine(gcm);

 

728x90

 

▶ 최대 공약수 구하기

#region 최대 공약수 구하기 - GetGreatestCommonDivisor(value1, value2)

/// <summary>
/// 최대 공약수 구하기
/// </summary>
/// <param name="value1">값 1</param>
/// <param name="value2">값 2</param>
/// <returns>최대 공약수</returns>
public uint GetGreatestCommonDivisor(uint value1, uint value2)
{
    while(value2 != 0)
    {
        uint remainder = value1 % value2;

        value1 = value2;
        value2 = remainder;
    }

    return value1;
}

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