C# 排列与组合

C# 排列与组合,c#,C#,我有四组值,即 S(which ranges from x to y with a variation of .5), C(which ranges from a to b with a variation of .25), A(which ranges from p to q with a variation of 1) Ad(which ranges from c to d with a variation of 1.5). 对于S的每个值,我应该从其他三个集合中获得所有可能的值组

我有四组值,即

 S(which ranges from x to y with a variation of .5),
 C(which ranges from a to b with a variation of .25),
 A(which ranges from p to q with a variation of 1)
 Ad(which ranges from c to d with a variation of 1.5).

对于S的每个值,我应该从其他三个集合中获得所有可能的值组合。你能帮我建议合适的代码吗……。

将所有值乘以某个常数,这样你就进入了“整数问题域”。然后为Si、Ci、Ai和Adi(S-整数、C-整数,…)制作4个嵌套循环。这样,您将获得所有组合。回到“浮点域”,用前面提到的常数除以

编辑: 忘记以前的建议吧。试着这样做:

  double x = 1.1, y = 5.1, a = 6.1, b = 7.1, p = 8.1, q = 9.1, c = 10.1, d = 15.1;
  double S, C, A, Ad;

  for (S=x; S <= y; S = S + .5)
    for (C=a; C <= b; C = C + .25)
      for (A=p; A <= q; A = A + 1.0)
        for (Ad=c; Ad <= d; Ad = Ad + 1.5)
          Console.WriteLine("S={0} C={1} A={2}, Ad={3}", S, C, A, Ad);
  Console.ReadLine();
double x=1.1,y=5.1,a=6.1,b=7.1,p=8.1,q=9.1,c=10.1,d=15.1;
双S,C,A,Ad;

对于(S=x;S)这不是一个要求为您编写代码的地方。最好寻求一般帮助。中有一个关于组合主题的伟大讨论。我特别喜欢Eric Lippert的解决方案。