#### C program for drawing a CIRCLE using Midpoint Circle Algorithm - CGMT

##### Mid-pt-Algo-for-Circle.txt

##### File size: 1.01 KB

**File content type:**
text/plain

**Category: **Assignment

**Course: **B.Tech.

**Semester: **3

```
#include<stdio.h>
#include<dos.h>
#include<graphics.h>
#include<conio.h>
void main() {
int gd=DETECT, gm=DETECT;
int r, x, y, midx, midy;
float p;
clrscr();
initgraph(&gd,&gm,"");
printf("Enter the Radius of circle : ");
scanf("%d",&r);
x=0;
y=r;
p=1.25 - r;
midx=getmaxx()/2; //To get the max position (Bottom-Right corner) of screen.
midy=getmaxy()/2; //Dividing by 2 to get the centre of screen.
do {
putpixel(midx+ x, midy+ y , 1); //All possible 8 combinations to draw 8 Segments
putpixel(midx- x, midy- y , 2);
putpixel(midx- x, midy+ y , 3);
putpixel(midx+ x, midy- y , 4);
putpixel(midx +y, midy+ x , 5);
putpixel(midx +y, midy -x , 6);
putpixel(midx -y, midy -x , 7);
putpixel(midx -y, midy +x , 8);
delay(20);
x++; //x will always increase , so it is incremented outside if-else
if(p<0) {
p=p+2*x+1;
} else {
y--; //y decrements only when p>=0
p=p+2*(x-y)+1;
}
} while(x<=y);
getch();
closegraph();
}
```

Added by **StAn**

##### Comments

*whatshot*Forum*launch*-
Recommended Books second semester GGSIPU Delhi
Posted in

**Semester 2** -
Improve confirmation page during signup
Posted in

**Feature requests** -
Better Writing Experience with SimpleMDE
Posted in

**Notices** -
Competitive Programming in Java - Beginner Part 1
Posted in

**Competitive Programming** -
Summarized rules and instructions.
Posted in

**Rules and Instructions**

*file_download*Study Material*launch*-
Applied maths - I (Differential Equation)
Catgegory:

**Notes** -
Applied Physics 2 Unit 4 Band Theory and Semiconductor Notes
Catgegory:

**Notes** -
Maths Practical - Matrices
Catgegory:

**Notes and Practical Files** -
Computer Graphics and Multimedia(CGMT) Question Paper Bhavya 2015
Catgegory:

**Question Papers** -
Applied Maths - I (Approximate Calculation)
Catgegory:

**Notes** -
Stld notes
Catgegory:

**Notes** -
Maths ztransform and difference equation
Catgegory:

**Books** -
Statistics
Catgegory:

**Notes** -
STLD Practical File
Catgegory:

**Practical Files** -
Physics Akash First Semester 2015 & 2016
Catgegory:

**Question Papers**