#include< stdio.h>
#include< graphics.h>
#include< conio.h>
void MID_POINT_CIRCLE(int x,int y,int r);
void circlePlot(int,int,int,int);
void main()
{
int x,y,r,gdriver=DETECT,gmode;
clrscr();
initgraph(&gdriver,&gmode,"");
printf("\nEnter point(x,y):");
scanf("%d %d",&x,&y);
printf("\nEnter radius:");
scanf("%d",&r);
MID_POINT_CIRCLE(x,y,r);
getch();
}
void MID_POINT_CIRCLE(int xCen,int yCen,int r)
{
int x=0;
int y=r;
int p=1-r;
circlePlot(xCen,yCen,x,y);
while(x < y)
{
x++;
if(p < 0)
p+=(2*x)+1;
else
{
y--;
p+=2*(x-y)+1;
}
circlePlot(xCen,yCen,x,y);
}
}
void circlePlot(int xCen,int yCen,int x,int y)
{
putpixel(xCen+x,yCen+y,WHITE);
putpixel(xCen-x,yCen+y,WHITE);
putpixel(xCen+x,yCen-y,WHITE);
putpixel(xCen-x,yCen-y,WHITE);
putpixel(xCen+y,yCen+x,WHITE);
putpixel(xCen-y,yCen+x,WHITE);
putpixel(xCen+y,yCen-x,WHITE);
putpixel(xCen-y,yCen-x,WHITE);
}
OUTPUT
#include< graphics.h>
#include< conio.h>
void MID_POINT_CIRCLE(int x,int y,int r);
void circlePlot(int,int,int,int);
void main()
{
int x,y,r,gdriver=DETECT,gmode;
clrscr();
initgraph(&gdriver,&gmode,"");
printf("\nEnter point(x,y):");
scanf("%d %d",&x,&y);
printf("\nEnter radius:");
scanf("%d",&r);
MID_POINT_CIRCLE(x,y,r);
getch();
}
void MID_POINT_CIRCLE(int xCen,int yCen,int r)
{
int x=0;
int y=r;
int p=1-r;
circlePlot(xCen,yCen,x,y);
while(x < y)
{
x++;
if(p < 0)
p+=(2*x)+1;
else
{
y--;
p+=2*(x-y)+1;
}
circlePlot(xCen,yCen,x,y);
}
}
void circlePlot(int xCen,int yCen,int x,int y)
{
putpixel(xCen+x,yCen+y,WHITE);
putpixel(xCen-x,yCen+y,WHITE);
putpixel(xCen+x,yCen-y,WHITE);
putpixel(xCen-x,yCen-y,WHITE);
putpixel(xCen+y,yCen+x,WHITE);
putpixel(xCen-y,yCen+x,WHITE);
putpixel(xCen+y,yCen-x,WHITE);
putpixel(xCen-y,yCen-x,WHITE);
}
OUTPUT