Last active
December 9, 2015 04:36
-
-
Save komkanit/45ddd5a9739dc8b71b4e to your computer and use it in GitHub Desktop.
nCr in C#
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
| 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(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thank you so much yehyeh