Click here to Skip to main content
11,480,847 members (64,530 online)
Click here to Skip to main content

GCD Simplified using lambda

, 8 May 2011 CPOL 7.2K 2
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... Pin
Richard Deeming11-May-11 6:57
memberRichard Deeming11-May-11 6:57 
Generalok Pin
Steven.Pinto6-May-11 19:09
memberSteven.Pinto6-May-11 19:09 
GeneralCool recursion! May I, however, recommend a better name? Ot... Pin
Chris Trelawny-Ross6-May-11 11:53
memberChris Trelawny-Ross6-May-11 11:53 
GeneralRe: Ok thanks Pin
Steven.Pinto6-May-11 19:11
memberSteven.Pinto6-May-11 19: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 | Terms of Use | Mobile
Web02 | 2.8.150520.1 | Last Updated 8 May 2011
Article Copyright 2011 by Steven.Pinto2000
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid