要求利用对称性根据方程:X*X+Y*Y=R*R 用" * "在DOS界面中输出一个圆
TC(XP)下运行
[CODE]
#include<stdio.h>
#include<graphics.h>
void MidPointCircle(int r,int color);
void CirclePoints(int x,int y,int color);
void main()
{
int gdriver=DETECT, gmode;
initgraph(&gdriver, &gmode," ");
setbkcolor(BLACK);
MidPointCircle(100,BLUE);
getch();
closegraph();
}
void MidPointCircle(int r,int color)
{
int x,y;
float d;
x=0;
y=r;
d=1.25-r;
CirclePoints(x,y,color);
while(x<y)
{
if(d<0)
d+=2*x+3;
else
{
d+=2*(x-y)+5;
y--;
}
x++;
CirclePoints(x,y,color);
}
}
void CirclePoints(int x,int y,int color)
{
putpixel(320+x,240+y,color);
putpixel(320+y,240+x,color);
putpixel(320-x,240+y,color);
putpixel(320+y,240-x,color);
putpixel(320+x,240-y,color);
putpixel(320-y,240+x,color);
putpixel(320-x,240-y,color);
putpixel(320-y,240-x,color);
}
[/CODE]