C Program to Draw a Circle

In this article, you will learn to draw a circle in C programming language. You must supply the appropriate information to draw the circle such as co-ordinates of the center, length of the radius and so on.

Advertisements

Problem Definition

We wish to draw a circle in C language using the builtin graphics header file. The function Circle() is called to draw a circle with radius n.

Advertisements

The program follows the steps given below:

  • Declare all variables.
  • Initialize the variables.
  • Intialize the graph and set path to bgi files.
  • Set the color for the circle.
  • Draw the circle.
  • Close the graph.

Program Code – Draw Circle

/* Program to draw a circle in C */
#include <stdio.h>
#include <graphics.h>
#include <stdlib.h>
#include <conio.h>

int main()
{
/* Variable declaration */

int gdriver, gmode;
int x, y, radius;

/* variable initialization */

gdriver = DETECT;

/* Graph initialization */

initgraph(&gdriver, &gmode, "d:\\turboc3\\bgi");


/* Set the color of the circle */

setcolor(CYAN);

/* Draw the CIRCLE */

x = 200;
y = 300;
radius = 100;

circle(x, y, radius);

getch();

/* close the graph */

closegraph();
return 0;

}

Output – Draw Circle

Output -Circle
Output – Circle

Advertisements

Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.