Click here to Skip to main content
11,411,494 members (64,578 online)
Click here to Skip to main content

GCD Simplified using lambda

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

Comments and Discussions

GeneralNot very efficient! Have a look at PinmemberRichard Deeming11-May-11 6:57 
Generalok PinmemberSteven.Pinto6-May-11 19:09 
GeneralCool recursion! May I, however, recommend a better name? Ot... PinmemberChris Trelawny-Ross6-May-11 11:53 
GeneralRe: Ok thanks PinmemberSteven.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
Web04 | 2.8.150414.5 | Last Updated 8 May 2011
Article Copyright 2011 by Steven.Pinto2000
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid