Arc function in C

In C programming, the arc() function is used to draw an arc (a portion of a circle's circumference) on the graphics screen. This function is part of the graphics.h library, which provides various drawing capabilities for creating graphical outputs.

Syntax

void arc(int x, int y, int startangle, int endangle, int radius);

Parameters

The arc() function accepts five parameters −

  • x − The x-coordinate of the center of the arc
  • y − The y-coordinate of the center of the arc
  • startangle − The starting angle of the arc in degrees (0-360)
  • endangle − The ending angle of the arc in degrees (0-360)
  • radius − The radius of the arc in pixels

Note: To use graphics functions, you need to install a graphics library like WinBGIm for modern compilers, as the traditional Turbo C graphics.h is not available in standard modern C environments.

Example

Here's how to draw an arc using the arc() function −

#include <graphics.h>
#include <conio.h>

int main() {
    int gd = DETECT, gm;
    int x = 250;
    int y = 250;
    int start_angle = 45;
    int end_angle = 135;
    int radius = 100;
    
    /* Initialize graphics mode */
    initgraph(&gd, &gm, "");
    
    /* Draw the arc */
    arc(x, y, start_angle, end_angle, radius);
    
    /* Wait for user input */
    getch();
    
    /* Close graphics mode */
    closegraph();
    
    return 0;
}

How It Works

The arc() function draws a circular arc by specifying the center point, start and end angles, and radius. Angles are measured in degrees, with 0° pointing to the right (3 o'clock position) and increasing counter-clockwise.

(x,y) 45° 135°

Key Points

  • The function draws only the arc outline, not a filled sector
  • Angles are specified in degrees (0-360)
  • The arc is drawn counter-clockwise from start angle to end angle
  • Graphics mode must be initialized before calling arc()

Conclusion

The arc() function is essential for drawing curved elements in C graphics programming. It provides precise control over arc positioning and dimensions, making it useful for creating charts, gauges, and decorative graphics elements.

Updated on: 2026-03-15T12:13:23+05:30

3K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements