【发布时间】:2022-01-08 10:50:08
【问题描述】:
#include <stdio.h>
#include <math.h>
#include <complex.h>
#define N_MAX 12
int Mandelbrot_equation (double x, double y, int n, double Zn) {
if (cabs(Zn) >= 2 || n >= N_MAX) return n;
if (n == 0) Zn = 0;
else {
Zn = cpow(Zn, 2 + 0 * I) + x + I * y;
}
Mandelbrot_equation(x, y, n + 1, Zn);
}
int main(int argc, char const *argv[]) {
for (double y = -2.0; y < 1.0; y += 0.1) {
for (double x = -1.0; x < 1.0; x += 0.1) {
if (Mandelbrot_equation(x,y,0,0) == N_MAX) printf(".");
else{
printf(" ");
}
if (x == 0.9) printf("\n");
}
}
return 0;
}
在上面的代码中,我尝试实现 Mandelbrot 递归并将其打印到屏幕上。 问题是输出如下:https://i.stack.imgur.com/c0LPe.png
我是不是把递归弄错了,还是等式弄错了?
【问题讨论】:
-
不要发布文字图片。将文本作为文本发布。阅读:How to Ask
-
锌不复杂
-
也许您可以添加预期输出的样子(?)
-
你的编译器应该警告你你没有从
Mandelbrot_equation()返回值。始终注意编译器消息。 -
请问您为什么选择将其实现为递归函数而不是使用简单的循环?