我有四组值,即
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的每个值,我应该从其他三个组中获得所有可能的值组合。您可以通过建议合适的代码来帮助我........
答案 0 :(得分:1)
将所有值乘以一些常量,以便进入“整数问题域”。然后为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();