Skip to content

Instantly share code, notes, and snippets.

@zsoumya
Created March 25, 2021 05:24
Show Gist options
  • Save zsoumya/5262523f9bbb430eb7b470358fed135a to your computer and use it in GitHub Desktop.
Save zsoumya/5262523f9bbb430eb7b470358fed135a to your computer and use it in GitHub Desktop.
GCF of any set of numbers
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