Hi
What is the best way to go forward with finding all possible combinations of
nCr
Eg:
5C3 for the number 12345

123
134
135
145
234
235
345

Like that

thanks

I picked this up online hope this can help.

Calculate the combinations for C(n,r) = n! / r! (n - r)!. For r <= n, n >= 0, and r >= 0.

that will give how many combinations are possible......but i want to display all the possible combinations.

This is the code I wrote for printing if the value of r is 3

import java.util.Scanner;
public class ncr
{
public static void main(String args[])
{
//Scanner s =new Scanner(System.in);
//int n,r;
//System.out.println("Eneter the value of n");
//n=s.nextInt();
//System.out.println("Enter the value of r");
//r=s.nextInt();
//System.out.println("Enter the number");
String[] number = {"1","2","3","4","5"};
for(int i=0;i<number.length;i++)
{
for(int j=i+1;j<number.length-1;j++)
{
int k=j+1;
System.out.println(number[i]+""+number[j]+""+number[(j+1)]);
}
}

}
}

I want to enhance this to get for any r using the same logic.......can u guys give any idea

Edited 3 Years Ago by mike_2000_17: Fixed formatting

Guys wht is this........I have posted ages ago and u guys cant help with this or wht.........sorry if im rude..........i tried my best......but im not able to proceed further.......and this is not my homework or anything.......its just something tht im interested in doing.........jus gimme a hint on how to proceed and ill do it......merci beacoup

Guys wht is this........I have posted ages ago and u guys cant help with this or wht.........sorry if im rude..........i tried my best......but im not able to proceed further.......and this is not my homework or anything.......its just something tht im interested in doing.........jus gimme a hint on how to proceed and ill do it......merci beacoup

Is your question regarding implementing the algorithm or writing the algorithm?

Hint:
This is a well established math algorithm; so why not take one of the existing methods and convert it to Java?

i tried searching for the algorithm but........there were actually some pretty wierd stuff tht i saw....so could u please post some links to the algorithm if u know any

and like i already said i want the algorithm to be able to generate the combinations and just not calculate the number of possible combinations as its pretyy easy using
n!/r!(n-r)!

If you don't understand the algorithm...how are you going to implement it? Take the time to write out manually (yes pen and paper) the algorithm step by step until you understand it. Convince yourself you know how it works, then start writing code.

no man........im not findin a proper algorithm.....its like these liks are jus citations and no proper algorithm......

if u know a link kindly post it and im pretty sure i can figure it out from there
merci beacoup

This article has been dead for over six months. Start a new discussion instead.