Introduction :
There are various functions are used in C or C++ graphics programming. One of them is arc() function that can be used in various applications such as graphics programs, creating clocks, pie charts, simple games, graphical user interfaces etc. It allows you to draw an arc with the given parameters (the center point, radius, start angle and end angle).
In this article, I shall show you how to use arc() function using the C or C++ graphics programming language. Here, I also show you the syntax and usage of arc() function.
What is arc() function :
The arc() function is a function of the graphics.h library in the Turbo C++ IDE. It is used in C or C++ graphics programming language to draw an arc or curve on the graphics screen. This function is useful to create circular shapes, sectors and curve designs.
Syntax of the arc() function :
In C or C++ graphics programming language, the following code is the syntax of the arc() function.
void arc(int x, int y, int a, int b, int r);
The arc() function does not return any value. It takes five parameters. The x and y parameters are the x and y coordinate of the center of the arc respectively. The a and b parameters are the starting angle and ending angle of the arc in degrees. The r is the radius of the arc.
About the program :
In this example, I show you how to draw an arc using C or C++ graphics programming language. When you run the program, you see a red color arc on black color graphical window. If you press any key, the program will be stopped.
Explanation of the program :
First, include the necessary header files such as graphics.h and conio.h in the program. In the main() function, declare variables such as “x”, “y”, “a”, “b”, “r”, “graphic_driver” and “graphic_mode”. Now, you can initialize the graphics mode using initgraph() function. You can use setcolor() function to set the drawing color of the arc.
Now, call the arc() function with parameters to draw the arc. The getch() and closegraph() are used to get a key press from user and close the graphics mode.
How run the program :
Now, install the Turbo C++ IDE on your PC. Then, create a C or C++ file in Turbo C++ IDE. After that, copy the below code and paste in the C or C++ file. Do you know how to copy paste in the Turbo C++ IDE. You can also know how to use graphics.h in Turbo C++ IDE from my link.
Source code of the program :
The following code is used for arc() function in C or C++ programming language.
/*Developed by Puskar Jasu*/
#include <graphics.h>
#include <conio.h>
int main()
{
int x = 300, y = 400, a = 30, b = 150, r = 200;
int graphic_driver = DETECT, graphic_mode;
initgraph(&graphic_driver, &graphic_mode, "//turboc3/bgi");
setcolor(4);
arc(x, y, a, b, r);
getch();
closegraph();
return 0;
}
Output of the program :
After running the program, you can see the output of the program on your PC.

Conclusion :
At last, you have learned how to draw arcs in C or C++ graphics programming language. Now you can use arc() function to develop more complex graphics applications. Thank you for visiting my site.