Created
March 25, 2021 05:24
-
-
Save zsoumya/5262523f9bbb430eb7b470358fed135a to your computer and use it in GitHub Desktop.
GCF of any set of numbers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void Main() | |
{ | |
FindGCF(154875, 137688, 182664).Dump(); | |
} | |
int FindGCF(params int[] nums) | |
{ | |
return nums.Aggregate((result, num) => GCF(result, num)); | |
} | |
int GCF(int num1, int num2) | |
{ | |
if (num2 == 0) | |
{ | |
return num1; | |
} | |
return GCF(num2, num1 % num2); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment