Mid Point

09:13 0 Comments A+ a-


Program:


#include<iostream.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
#include<math.h>
void main()
{
float d;
int gd=DETECT,gm,x,y,r;
clrscr();
initgraph(&gd,&gm,"c:\\tc\\bgi");
cout<<"Enter the radius of a circle: ";
cin>>r;
x=0;
y=r;
d=1.25-r;
do
{
putpixel(350+x,350+y,10);
putpixel(350+y,350+x,11);
putpixel(350+x,350-y,17);
putpixel(350+y,350-x,18);
putpixel(350-x,350-y,12);
putpixel(350-x,350+y,20);
putpixel(350-y,350+x,21);
putpixel(350-y,350-x,11);
if (d<=0)
{
x=x+1;
y=y;
d=d+2*x+1;
}
else
{
x=x+1;
y=y-1;
d=d+2*(x-y)+1;
}
}
while(x<=y);
getch();
closegraph();
}