Here is a C# function to find the greatest common divisor (GCD) of two integers using the Euclidean algorithm:
main.cs151 chars11 lines
To use this function, you can simply call it and pass in your two numbers:
main.cs39 chars2 lines
This function works by repeatedly finding the remainder of a
divided by b
, and setting a
to b
and b
to the remainder. This continues until b
is zero, at which point a
represents the GCD of the original two numbers.
gistlibby LogSnag