```
#include
#include
#include
#include
#include
void driver()
{
int gd=DETECT,gmode;
initgraph(&gd,&gmode,"c:\\tc\\bgi");
}
void circlept(int xcentre,int ycentre,int x,int y,int radius)
{
putpixel(xcentre+x,ycentre+y,RED);
putpixel(xcentre-x,ycentre+y,RED);
putpixel(xcentre+x,ycentre-y,RED);
putpixel(xcentre-x,ycentre-y,RED);
putpixel(xcentre+y,ycentre+x,RED);
putpixel(xcentre-y,ycentre+x,RED);
putpixel(xcentre+y,ycentre-x,RED);
putpixel(xcentre-y,ycentre-x,RED);
}
void midptcircle(int xcentre,int ycentre,int radius)
{
int p,x,y;
x=0;
y=radius;
p=1-radius;
circlept(xcentre,ycentre,x,y,radius);
while(x<y)
{
if(p<0)
x++;
else
{
x++;
y--;
}
if(p<0)
p=p+ 2*x +1;
else
p=p+2*(x-y)+1;
circlept(xcentre,ycentre,x,y,radius);
}
}
void main()
{
int xcentre,ycentre,radius;
driver();
getch();
setbkcolor(DARKGRAY);
cleardevice();
printf("\n Enter x co-ordinate of centre::\t");
scanf("%d",&xcentre);
printf("\n Enter y co-ordinate of centre::\t");
scanf("%d",&ycentre);
printf("\n Enter Radius of the circle:: \t");
scanf("%d",&radius);
cleardevice();
midptcircle(xcentre,ycentre,radius);
getch();
closegraph();
}
```
</div>
Leave a comment