//Program to plot a circle by Bresanham's 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,p;  
	p=3-2*r;  
	while (x<y)  
	{  
		if (p<0)  
		{  
			p+=2*(2*x+3);  
			x++;  
		}  
		else  
		{  
			x++,y;  
			p+=2*(2*x+5)-4*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();  
}