Click here to Skip to main content
13,006,180 members (70,463 online)
Click here to Skip to main content
Add your own
alternative version


2 bookmarked
Posted 6 May 2011

GCD Simplified using lambda

, 8 May 2011
Rate this:
Please Sign up or sign in to vote.
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.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

United States United States
No Biography provided
Group type: Social Group (No members)

You may also be interested in...


Comments and Discussions

GeneralNot very efficient! Have a look at Pin
Richard Deeming11-May-11 5:57
memberRichard Deeming11-May-11 5:57 
Generalok Pin
Steven.Pinto6-May-11 18:09
memberSteven.Pinto6-May-11 18:09 
GeneralCool recursion! May I, however, recommend a better name? Ot... Pin
Chris Trelawny-Ross6-May-11 10:53
memberChris Trelawny-Ross6-May-11 10:53 
GeneralRe: Ok thanks Pin
Steven.Pinto6-May-11 18:11
memberSteven.Pinto6-May-11 18:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170628.1 | Last Updated 8 May 2011
Article Copyright 2011 by Steven.Pinto2000
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid