15,919,749 members
See more:
Hi all,

I need to find combinations, and calculate values for the resultant combinations by substituting values..

C#
```string[] str=new string[]{"A","B","C","D"};
double[] vals=new double[]{1,3,6,9};```

A=1;
B=3;
C=6;
D=9

Say N=4,M=3;// N and M are Dynamic values
N-M+1=2;

so i want to find combinations for str with N-M+1 Value ie 4C2 = 6.
i am getting 6 Combinations.
AB
AC
BC
BD
CD..

finally i want to calculate & store the combination values in another Array..

I used below code, it works for N=4,M=2
```for (int j = 0; j < factval; j++)//factval,faval is FactorialValue ie 4C3 Combination Value
{
for (int k = 0; k < PFDdu.Length; k++)//PFDdu is str Length
{
if (!string.IsNullOrEmpty(PFDdu[(k + 1) % PFDdu.Length].ToString()))
{
if (j != (k + 1) % PFDdu.Length)
{
faval[j] = faval[j] * PFDdu[(k + 1) % PFDdu.Length];
}
}
}
}```

Can any body help me on this plz..

with Regards,
Pawan.
Posted
Updated 2-Mar-11 4:21am
v3

## Solution 1

Does this help?
Combinatorial algorithms in C#[^]

Permutations, Combinations, and Variations using C# Generics[^]

Search on google, I am sure you will find.

v2
Pawan Kiran 2-Mar-11 9:53am
it doesn't help me to overcome my issue..
Olivier Levrey 2-Mar-11 10:07am
Pawan Kiran 2-Mar-11 12:01pm
vote of 5..
solves my issue.. thank u very much..
Olivier Levrey 2-Mar-11 12:10pm
you're welcome ;)
you may also click the "accept answer" button to show it is solved.
Sergey Alexandrovich Kryukov 2-Mar-11 13:04pm
Pawan, do accept Olivier's Answer, it's good.
My 5, too.
--SA