Sunday, 1 July 2012

program to draw a circle in c++.

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
void circlepoints(int,int,int,int);
void main()
{
int xc,yc,r;
int x,y,p;
int gd,gm;
detectgraph(&gd,&gm);
initgraph(&gd,&gm," ");
x=0;
printf("enter the value of xcenter:");
scanf("%d",&xc);
printf("enter thye value of ycenter:");
scanf("%d",&yc);
printf("enter value of radiius:");
scanf("%d",&r);
y=r;    p=1-r;
circlepoints(xc,yc,x,y);
while(x<y)
{
x++;
if(p<0)
{p+=2*x+1;
}
else{
y--;
p+=2*(x-y)+1;
}
circlepoints(xc,yc,x,y);
}
getch();
}
void circlepoints(xc,yc,x,y)
{
putpixel(xc+x,yc+y,3);
putpixel(xc-x,yc+y,4);
putpixel(xc+x,yc-y,6);
putpixel(xc-x,yc-y,5);
putpixel(xc+y,yc+x,7);
putpixel(xc-y,yc+x,3);
putpixel(xc+y,yc-x,4);
putpixel(xc-y,yc-x,2);
}