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

TestProject.zip
0.01MB

▶ MainForm.cs

using System;
using System.Windows.Forms;

namespace TestProject
{
    /// <summary>
    /// 메인 폼
    /// </summary>
    public partial class MainForm : Form
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 생성자 - MainForm()

        /// <summary>
        /// 생성자
        /// </summary>
        public MainForm()
        {
            InitializeComponent();

            #region 이벤트를 설정한다.

            this.btnGo.Click += runButton_Click;

            #endregion
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Private
        //////////////////////////////////////////////////////////////////////////////// Event

        #region 실행 버튼 클릭시 처리하기 - runButton_Click(sender, e)

        /// <summary>
        /// 실행 버튼 클릭시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void runButton_Click(object sender, EventArgs e)
        {
            long a = long.Parse(this.txtA.Text);
            long b = long.Parse(this.txtB.Text);

            this.gcdTextBox.Text = GetGreatestCommonDivisor(a, b).ToString();
            this.lcmTextBox.Text = GetLeastCommonMultiple(a, b).ToString();
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////// Function

        #region 최대 공약수 구하기 - GetGreatestCommonDivisor(a, b)

        /// <summary>
        /// 최대 공약수 구하기
        /// </summary>
        /// <param name="a">A</param>
        /// <param name="b">B</param>
        /// <returns>최대 공약수</returns>
        private long GetGreatestCommonDivisor(long a, long b)
        {
            a = Math.Abs(a);
            b = Math.Abs(b);

            for(; ; )
            {
                long remainder = a % b;

                if(remainder == 0)
                {
                    return b;
                }

                a = b;
                b = remainder;
            };
        }

        #endregion
        #region 최소 공배수 구하기 - GetLeastCommonMultiple(a, b)

        /// <summary>
        /// 최소 공배수 구하기
        /// </summary>
        /// <param name="a">A</param>
        /// <param name="b">B</param>
        /// <returns>최소 공배수</returns>
        private long GetLeastCommonMultiple(long a, long b)
        {
            return a * b / GetGreatestCommonDivisor(a, b);
        }

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