//Program to plot a circle by Mid-Point Approach  

#include <iostream.h>  
#include <graphics.h>  
#include <math.h>  
#include <conio.h>  
void drawcircle(int x1, int y1, int r)  
{  
  int x=0,y=r,d;  
  d=1-r;  
  while (x<y)  
  {  
    if (d<0)  
    {  
      d+=2*x+3;  
      x++;  
    }  
    else  
    {  
      x++,y--;  
      d+=2*x+5-2*y;  
    }  
    putpixel(x+getmaxx()/2+x1,y+getmaxy()/2-y1,5);  
    putpixel(-x+getmaxx()/2+x1 ,y+getmaxy()/2-y1,5);  
    putpixel(x+getmaxx()/2+x1,-y+getmaxy()/2-y1,5);  
    putpixel(-x+getmaxx()/2+x1,-y+getmaxy()/2-y1,5);  
    putpixel(y+getmaxx()/2+x1,x+getmaxy()/2-y1,5);  
    putpixel(-y+getmaxx()/2+x1,x+getmaxy()/2-y1,5);  
    putpixel(y+getmaxx()/2+x1,-x+getmaxy()/2-y1,5);  
   putpixel(-y+getmaxx()/2+x1,-x+getmaxy()/2-y1,5);  
  }  
}  
void main()  
{  
  int x1, y1, r;  
  int gdriver = DETECT, gmode, errorcode;  
  initgraph(&gdriver, &gmode, "");  
  line(0,getmaxy()/2,getmaxx(),getmaxy()/2);  
  line(getmaxx()/2,0,getmaxx()/2,getmaxy());  
  cout<<"Enter x1 ";  
  cin>>x1;  
  cout<<"Enter y1 ";  
  cin>>y1;  
  cout<<"Enter r ";  
  cin>>r;  
  drawcircle(x1,y1,r);  
  getch();  
}