#include <stdio.h>
#include <graphics.h>
#include <conio.h>
void draw_circle(int,int,int);
void main()
{
int gd=DETECT,gm;
int r;
int xcen,ycen;
initgraph(&gd,&gm,"c:\\tc\\");
//clrscr();
printf("enter radius :");
scanf("%d",&r);
printf("enter circle centre coordinate :");
scanf("%d%d",&xcen,&ycen);
draw_circle(xcen,ycen,r);
getch();
}
void draw_circle(int xcen,int ycen,int r)
{
int x,y,p;
x=0;
y=r;
p=1-r;
putpixel(xcen+x,ycen+y,12);
putpixel(xcen-x,ycen+y,12);
putpixel(xcen+x,ycen-y,12);
putpixel(xcen-x,ycen-y,12);
putpixel(xcen+y,ycen+x,12);
putpixel(xcen+y,ycen-x,12);
putpixel(xcen-y,ycen+x,12);
putpixel(xcen-y,ycen+x,12);
while(x<=y)
{
if(p<0)
p=p+2*x+1;
else
{
p=p+2*(x-y)+1;
y--;
}
x++;
putpixel(xcen+x,ycen+y,10);
putpixel(xcen-x,ycen+y,11);
putpixel(xcen+x,ycen-y,12);
putpixel(xcen-x,ycen-y,11);
putpixel(xcen+y,ycen+x,14);
putpixel(xcen+y,ycen-x,11);
putpixel(xcen-y,ycen-x,13);
putpixel(xcen-y,ycen+x,11);
}
}
#include <graphics.h>
#include <conio.h>
void draw_circle(int,int,int);
void main()
{
int gd=DETECT,gm;
int r;
int xcen,ycen;
initgraph(&gd,&gm,"c:\\tc\\");
//clrscr();
printf("enter radius :");
scanf("%d",&r);
printf("enter circle centre coordinate :");
scanf("%d%d",&xcen,&ycen);
draw_circle(xcen,ycen,r);
getch();
}
void draw_circle(int xcen,int ycen,int r)
{
int x,y,p;
x=0;
y=r;
p=1-r;
putpixel(xcen+x,ycen+y,12);
putpixel(xcen-x,ycen+y,12);
putpixel(xcen+x,ycen-y,12);
putpixel(xcen-x,ycen-y,12);
putpixel(xcen+y,ycen+x,12);
putpixel(xcen+y,ycen-x,12);
putpixel(xcen-y,ycen+x,12);
putpixel(xcen-y,ycen+x,12);
while(x<=y)
{
if(p<0)
p=p+2*x+1;
else
{
p=p+2*(x-y)+1;
y--;
}
x++;
putpixel(xcen+x,ycen+y,10);
putpixel(xcen-x,ycen+y,11);
putpixel(xcen+x,ycen-y,12);
putpixel(xcen-x,ycen-y,11);
putpixel(xcen+y,ycen+x,14);
putpixel(xcen+y,ycen-x,11);
putpixel(xcen-y,ycen-x,13);
putpixel(xcen-y,ycen+x,11);
}
}
No comments:
Post a Comment