65.9K
CodeProject is changing. Read more.
Home

GCD Simplified using lambda

starIconstarIconstarIconstarIconemptyStarIcon

4.00/5 (3 votes)

May 6, 2011

CPOL
viewsIcon

15413

Get GCD

Here is a trick which simplifies GCD using Lambda expression:
Func<int,int,int> GCDrecussion = null;
              GCDrecussion = (z,x) => x == 0 ? z : GCDrecussion(x, z % x);
             Console.WriteLine(GCDrecussion(4, 6));
The Function GCDrecussion takes 2 parameters; both are of int type, in my case I have passed 4 and 6 and the function returns int.