Introduction :
Drawing shapes and patterns is a basic task in graphics program. During develop graphics program, you have to draw circles on the screen. Using circle() function of graphics.h library, you can easily draw circles with a specified center and radius. In this article, I shall show you how to use circle() function using C or C++ graphics programming language. Here, I also show you the syntax and usage of circle() function.
What is circle() function :
The circle() function is an important function of the graphics.h library in Turbo C++ IDE. Using C or C++ programming language, you can draw circles on the graphics screen. You have to specify the coordinates of the center and the radius of the circle to draw a circle on the screen.
Syntax of the circle() function :
In C or C+ programming language the following code is the syntax of circle() function.
void circle(int x, int y, int r);
The return value of circle() function is void that means it returns no value. It takes three integer parameters. The first (x) and second (y) parameters are the x and y coordinate of the center of the circle respectively. The third (r) parameter is the radius of the circle.
About the program :
In this example, I shall show you how to draw a circle using C or C++ graphics programming language. When you run the program on your PC, you can see a circle with red color on the graphics screen. If you press any key, the program will be stopped.
Explanation of the program :
At first, you have to include header files such as graphics.h and conio.h in the program. Then, declare variables such as “x”, “y”, “r”, “graphic_driver” and “graphic_mode” in the main() function. After that, initialize the graphics mode using initgraph() function. To set the drawing color of the circle, you can use setcolor() function.
Now, call circle() function that draws a circle with radius of 50 pixels on the screen. You can use getch() function that takes a key press from the user. Lastly, close the graphics mode using closegraph() function.
How run the program :
Now, install the Turbo C++ IDE on your PC. Then, open the Turbo C++ and create a C or C++ file in it. After that, copy the below code and paste in the file which you have just created. Do you know how to copy paste in the Turbo C++ IDE? You have to also know how to use graphics.h in Turbo C++ IDE.
Source code of the program :
The following code is the source code of the program where you see how to use circle() function.
/*Developed by Puskar Jasu*/
#include <graphics.h>
#include <conio.h>
int main()
{
int x = 300, y = 200, r = 50;
int graphic_driver = DETECT, graphic_mode;
initgraph(&graphic_driver, &graphic_mode, "//turboc3/bgi");
setcolor(4);
circle(x, y, r);
getch();
closegraph();
return 0;
}
Output of the program :
When you run the program, you can see the output of the program on your PC.

Conclusion :
At last, you have learned how to use circle() function in the C or C++ graphics programming language. Now you can use circle() function and create your own programs. Thank you for visiting my site.