decalaration sytax error

来源:百度知道 编辑:UC知道 时间:2024/05/10 17:51:59
#include<graphics.h>
typedef struct{float x,y;}
complex complexSquare(complex c)
{ complex csq;
csq.x=c.x*c.x-c.y*c.y;
csq.y=2*c.x*c.y;
return csq;
}
int interate(complex zInit,int maxIter)
{
complex z=zInit;
int cnt=0;
while((z.x*z.x+z.y*z.y<=4.0)&&(cnt<maxIter))
{
z=complexSquare(z);
z.x+=zInit.x;
z.y+=zInit.y;
cnt++;
}
return cnt;
}
void mandelbrot(int nx,int ny,int maxIter,float realMin,float realMax,float imagMin,float imagMax)
{
float realInc=(realMax-realMin)/nx;
float imagInc=(imagMax-imagMin)/ny;
complex z;
int x,y;
int cnt;
for(x=0,z.x=realMin;x<nx;x++,z.x+=imagInc)
{
for(y=0,z.y=imagMin;y<ny;y++,z.y+=imagInc)
{
cnt=iterate(z,maxIter);
if(cnt==maxIter)
putpixel(x,y,BLACK);
else
putpixel(x,y,cnt);
}
}
}
void main()
{
int gd

有一些语法错误,修改如下(绘制出的图形很特别!呵呵.):

#include<graphics.h>
typedef struct{float x,y;} complex;/*注意这里*/
complex complexSquare(complex c)
{ complex csq;
csq.x=c.x*c.x-c.y*c.y;
csq.y=2*c.x*c.y;
return csq;
}
int interate(complex zInit,int maxIter)
{
complex z=zInit;
int cnt=0;
while((z.x*z.x+z.y*z.y<=4.0)&&(cnt<maxIter))
{
z=complexSquare(z);
z.x+=zInit.x;
z.y+=zInit.y;
cnt++;
}
return cnt;
}
void mandelbrot(int nx,int ny,int maxIter,float realMin,float realMax,float imagMin,float imagMax)
{
float realInc=(realMax-realMin)/nx; /*变量realInc没有使用*/
float imagInc=(imagMax-imagMin)/ny;
complex z;
int x,y;
int cnt;
for(x=0,z.x=realMin;x<nx;x++,z.x+=imagInc)
{
for(y=0,z.y=imagMin;y<ny;y++,z.y+=imagInc)
{
cnt=interate(z,maxIter); /*注意这里*/
if(cnt==maxIter)
putpixel(x,y,BLACK);
else
putpixel(x,y,cnt)