Returns the greatest common divisor of two numbers - CSharp System

CSharp examples for System:Math Number

Description

Returns the greatest common divisor of two numbers

Demo Code


using System.Text;
using System.Linq;
using System.Collections.Generic;
using System;/*  w  ww. jav a 2s.c om*/

public class Main{
        /// <summary>
        /// Returns the greatest common divisor of two numbers
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <returns></returns>
        public static int GCD(int a, int b)
        {
            if (b == 0) return a;
            else return GCD(b, a % b);
        }
}

Related Tutorials