Wednesday , September 20 2017
Home / C / C program for drawing a circle using Midpoint Circle Algorithm

C program for drawing a circle using Midpoint Circle Algorithm

Here is given a C program for Midpoint of a Circle using Bresenhams Midpoint circle algorithm. The program is made using C Graphics and the output figure is shown below the code.

#include<graphics.h>
#include<conio.h>
#include<stdio.h>
void main()
{
int gd=DETECT,gm;
int i,r,x=0,y,xc,yc;
float d;
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=1.25-r;
y=r;
do
{
if(d<0.0)
{

x=x+1;
d=d+2*x+1;
}
else
{

x=x+1;
y=y-1;
d=d+2*x-2*y+10;
}
&nbsp;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);
}
while(x<y);
getch();
}

 

Output

Tags: Midpoint circle algorithm, c program for Midpoint circle algorithm , graphics program for midpoint circle algorithm

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 ...

7 comments

  1. That is the great program. I will surely share that.

  2. pls explain this coding

  3. gajanan chanagond

    good program

  4. in second condition pk it should be +1 instead of +10

  5. Hey is that code correct where x=; and at if(d<)

    The compiler gives invalid expression here..??

Leave a Reply

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