循环所有数字组合 [英] looping all number combinations
问题描述
我的工作是应该全自动测试值,看看是否有一个意外的错误测试功能。
I'm working on a test function that is supposed to test values automaticly to see if there is an unexpected error.
有一个应该具有-999之间的值范围为1000六大持有人
There are six "holders" that is supposed to have a value range between -999 to 1000
这是我试了一下:
#include <stdlib.h>
#include <stdio.h>
int inuti(double x, double y, double x1, double y1, double x2, double y2) {
int x_inuti;
int y_inuti;
if (x1 < x2)
x_inuti = x > x1 && x < x2;
else
x_inuti = x > x2 && x < x1;
if (y1 < y2)
y_inuti = y > y1 && y < y2;
else
y_inuti = y > y2 && y < y1;
return x_inuti && y_inuti;
}
int main(void) {
double x, y, x1, y1, x2, y2;
int resultat;
x = -999;
y = 1000;
x1 = -999;
y1 = 1000;
x2 = -999;
y2 = 1000;
while (x<1000 && y>-999 && x1<1000 && y2 >-999 && x2<1000 && y2>-999) {
x++;
y--;
y1++;
x1--;
x2++;
y2--;
printf("point x-value: %.1f \n", x);
printf("point y-value: %.1f \n", y);
printf("\n");
printf("corner side x-value: %.1f \n", x1);
printf("corner side y-value: %.1f \n", y1);
printf("\n");
printf("other corner side x-value%.1f \n", x2);
printf("other corner side y-value%.1f \n", y2);
printf("\n");
resultat = inuti(x, y, x1, y1, x2, y2);
if (resultat == 1)
printf("point was inside rectangle.\n");
else
printf("point was outside rectangle.\n");
printf("\n");
printf("\n");
}
getchar();
return 0;
}
然而,它并不包括所有的组合,它甚至超过了最大和最小数目。
However it doesn't include all combinations and it even exceeds the maximum and minimum number.
有谁知道循环更好的方法所有组合?
Does anyone know a better way to loop all combinations?
我AP preciate所有帮助
I appreciate all help
感谢
推荐答案
您会需要在6个不同的循环测试所有可能的不同组合。
You're going to need at 6 different loops to test all different possible combinations.
for (x = -999; x <= 1000; x++) {
for (y = -999; y < 1000; y++) {
for (x1 = -999; x1 <= 1000; x1++) {
// etc...
}
}
}
但要知道,有2000个 6 = 64,000,000,000,000,000,000不同的组合,意为code将pretty太多写不完执行(如果每个测试需要1微秒,在$ C $按c完成后约2028080年执行)。更好的选择是尝试测试,你知道输出的具体意见。请确保您测试的边缘情况了。
However be aware that there are 20006 = 64,000,000,000,000,000,000 different combinations, meaning the code will pretty much never finish executing (if each test takes 1 microsecond, the code will finish executing after about 2,028,080 years). A better option is to try testing specific inputs where you know the output. Make sure you test the edge cases too.
这篇关于循环所有数字组合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!