Home / C / C Program for Drawing a Circle using Bresenham Circle Algorithm

C Program for Drawing a Circle using Bresenham Circle Algorithm

#include<graphics.h>
#include<conio.h>
#include<stdio.h>
void main()
{
int gd=DETECT,gm;
int d,r,x,y,xc,yc;
clrscr();
initgraph(&gd,&gm,"c:\\tc\\");
printf("Enter Radius\n");
scanf("%d",&r);
printf("Enter Center of circle\n");
scanf("%d",&xc);
scanf("%d",&yc);
d=3-2*r;
x=0;
y=r;
while(x<=y)
{
putpixel(xc+x,yc+y,5);
putpixel(xc-y,yc-x,5);
putpixel(xc+y,yc-x,5);
putpixel(xc-y,yc+x,5);
putpixel(xc+y,yc+x,5);
putpixel(xc-x,yc-y,5);
putpixel(xc+x,yc-y,5);
putpixel(xc-x,yc+y,5);
if(d<=0)
{
d=d+4*x+6;
}
else
{
d=d+4*x-4*y+10;
y=y-1;
}
x=x+1;
}
getch();
}

Output:

C program for Bresenhams circle algorithm
Tags: C program for drawing a circle using Bresenhams circle algorithm, C program for Bresenhams circle algorithm
Also See:   C Program for Add two Numbers Using Pointers without Operators

Check Also

How to Solve Linear Equation in One Variable In C Programming?

C Program to Solve any Linear Equation in One Variable Find complete C program to ...

One comment

  1. thanks the code is simple an easily undersatndable

Leave a Reply

Your email address will not be published. Required fields are marked *