Skip to content

Instantly share code, notes, and snippets.

@komkanit
Last active December 9, 2015 04:36
Show Gist options
  • Select an option

  • Save komkanit/45ddd5a9739dc8b71b4e to your computer and use it in GitHub Desktop.

Select an option

Save komkanit/45ddd5a9739dc8b71b4e to your computer and use it in GitHub Desktop.
nCr in C#
using System;
class combi
{
static int[] arr;
public static void Main()
{
arr = new int[] {1,2,3,4,5};
Cal(3,0,new int[3]);
}
static void Cal(int len,int start,int[] result)
{
if(len == 0)
{
Print(result);
return;
}
for(int i = start ; i<=arr.Length-len ; i++)
{
result[result.Length-len] = arr[i];
Cal(len-1,i+1,result);
}
}
static void Print(int[] arr)
{
int len = arr.Length;
for(int i=0 ; i<len ; i++)
{
Console.Write(arr[i] + " ");
}
Console.WriteLine();
}
}
@tidjungs

tidjungs commented Dec 9, 2015

Copy link
Copy Markdown

thank you so much yehyeh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment