HOT C PROGRAMS BLOGSPOT

HOT C PROGRAMS BLOGSPOT

Click On Related Results For More Information

Thursday 11 October 2012

Graphics MidPoint Mid Point Circle C Program

/* .......Works on Win XP */

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
int x1,y1;
void pt(int x,int y)
{putpixel(x+x1,y+y1,RED);
putpixel(-x+x1,y+y1,RED);
putpixel(-y+x1,x+y1,RED);
putpixel(-y+x1,-x+y1,RED);
putpixel(-x+x1,-y+y1,RED);
putpixel(x+x1,-y+y1,RED);
putpixel(y+x1,-x+y1,RED);
putpixel(y+x1,x+y1,RED);
}
void main()
{
int r,gd=DETECT,gm,x,y,d;
clrscr();
initgraph(&gd,&gm,"C:\\TC\\BGI");   /*Sometimes it may be "c:\\tc\\bgi" , It depends machine to mac..*/
printf("enter radius");
scanf("%d",&r);
printf("enter center of the circle-");
scanf("%d%d",&x1,&y1);
x=0;
y=r;
d=1-r;
while(x<=y)
{
pt(x,y);
if(d<0)
d=d+2*x+3;
else
{d=d+2*(x-y)+5;
y--;

}
x++;
}
getch();
closegraph();
}

2 comments: