Click here to Skip to main content
12,448,709 members (52,932 online)
Click here to Skip to main content
Add your own
alternative version

Stats

8.8K views
2 bookmarked
Posted

GCD Simplified using lambda

, 8 May 2011 CPOL
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)



You may also be interested in...

Pro
Pro

Comments and Discussions

 
GeneralNot very efficient! Have a look at http://en.wikipedia.org/w... 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.

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