Click here to Skip to main content
Click here to Skip to main content
Go to top

GCD Simplified using lambda

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

License

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

Share

About the Author

Steven.Pinto2000

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



Comments and Discussions

 
GeneralNot very efficient! Have a look at http://en.wikipedia.org/w... PinmemberRichard Deeming11-May-11 5:57 
Generalok PinmemberSteven.Pinto6-May-11 18:09 
GeneralCool recursion! May I, however, recommend a better name? Ot... PinmemberChris Trelawny-Ross6-May-11 10:53 
GeneralRe: Ok thanks PinmemberSteven.Pinto6-May-11 18:11 

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

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

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