gpt4 book ai didi

c - 打印 Mandelbrot 集时循环不会因未知原因关闭

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

我正在尝试打印在空格和星号中设置的曼德尔布罗特集,但由于某种原因,该代码产生了无限的空格集。

循环确实关闭了,我重置了所有变量,但它不起作用。我很困惑,如果能得到一些帮助就太好了。

#include <stdlib.h>
#include <stdio.h>
#include <assert.h>


#define MAX_HOROZ 2
#define MAX_VERT 2
#define MAX_ITERATION 255
#define PIXEL_SIZE 0.0078125 //4/512

int main (int argc, char* argv[]) {

double row = -2; // y
double col = -2; // x
double xtemp;
double realValue;
double imagValue;
int iteration = 0;

while (row < MAX_VERT) {
while (col < MAX_HOROZ) {
imagValue = 0;
realValue = 0;
iteration = 0;
while ((iteration < MAX_ITERATION)&&
((realValue*realValue +imagValue*imagValue)< 4)) {
xtemp = realValue*realValue +imagValue*imagValue +col;
imagValue = 2*realValue*imagValue +row;
realValue = xtemp;
iteration++;
}
if (iteration == MAX_ITERATIONS) {
printf ("*");
}
else {
printf(" ");
}
col += PIXEL_SIZE;
}
row = 0;
printf("\n");
row += PIXEL_SIZE;

}


return EXIT_SUCCESS;
}

最佳答案

row = 0;
...
row += PIXEL_SIZE;

在底部。所以,当检查while (row < MAX_VERT)时,变量row-2-2 + PIXEL_SIZE .

也许你的意思是col = 0;而不是row = 0;

关于c - 打印 Mandelbrot 集时循环不会因未知原因关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29714883/

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