gpt4 book ai didi

c - 为什么我的循环不运行

转载 作者:行者123 更新时间:2023-11-30 21:30:01 25 4
gpt4 key购买 nike

我通过循环字母和数字来测试运行值。但是,由于某种原因,仅运行数字循环。

    #include <stdlib.h>
#include <stdio.h>
#include <limits.h>
#include <ctype.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;
char text_x, text_y, text_x1, text_y1, text_x2, text_y2;
int resultat;
int i;



char tecken[] = "abcdefgABCDEFG.+-";
char teckenback[] = "-+.GFEDXBAgfedcba";
int max;
int maxback;
max = strlen(tecken);
maxback = strlen(teckenback);

//These loops do only run if the number loops are commented.

for (i = 0; i < max; i++) {
for (i = 0; i < maxback; i++) {
for (i = 0; i < max; i++) {
for (i = 0; i < maxback; i++) {
for (i = 0; i < max; i++) {
for (i = 0; i < maxback; i++) {




text_x = tecken[i];
text_y = teckenback[i];
text_x1 = tecken[i];
text_y1 = teckenback[i];
text_x2 = tecken[i];
text_y2 = teckenback[i];


printf("punktens x-varde: %c \n", text_x);


printf("punktens y-varde: %c \n", text_y);

printf("\n");

printf("Ena hornets x-varde: %c \n", text_x1);


printf("Ena hornets y-varde: %c \n", text_y1);

printf("\n");

printf("Andra hornets x-varde %c \n", text_x2);


printf("Andra hornets y-varde %c \n", text_y2);

printf("\n");

printf("##### Endast nummer tillatet! #####");
printf("\n");
printf("\n");

}
}
}
}
}
}




for (x = 0; x <= 3; x++) {
for (y = 0; y <= 3; y++) {
for (x1 = 0; x1 <= 3; x1++) {
for (y1 = 0; y1 <= 3; y1++) {
for (x2 = 0; x2 <= 3; x2++) {
for (y2 = 0; y2 <= 3; y2++){

printf("punktens x-varde: %.1f \n", x);


printf("punktens y-varde: %.1f \n", y);

printf("\n");

printf("Ena hornets x-varde: %.1f \n", x1);


printf("Ena hornets y-varde: %.1f \n", y1);

printf("\n");

printf("Andra hornets x-varde %.1f \n", x2);


printf("Andra hornets y-varde %.1f \n", y2);

printf("\n");

resultat = inuti(x, y, x1, y1, x2, y2);


if (resultat == 1)
printf("Punkten var inuti rektangeln.\n");
else
printf("Punkten var utanfor rektangeln.\n");

printf("\n");
printf("\n");


}
}
}
}
}
}

getchar();
return 0;
}

如果我注释掉数字循环,字母循环会正常运行,但是当我运行整个代码时,只会运行数字循环。没有给出错误。有谁知道为什么会发生这种情况?谢谢您

最佳答案

在第一个循环部分中,如果 maxback 高于 max,则只有最后一个循环才会工作。在另一种情况下,如果 maxback 比 max 低 1,它将结束,因为在最后一次迭代之后,您已到达上述循环的末尾。在任何其他情况下,最后两个循环将无限期地运行。

简而言之,我的答案是:因为第一个循环没有完成,所以第二个循环不会运行。

关于c - 为什么我的循环不运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28326371/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com