Draw Line, Rectangle, Circle


Explanation

The graphics.h library in Turbo C provides functions to draw different shapes on the graphics screen. In this program, a circle, lines, and a rectangle are drawn using built-in graphics functions.

How It Works?

  • Step 1: Include the graphics.h header file.
  • Step 2: Initialize the graphics mode using initgraph().
  • Step 3: Set the drawing color using setcolor().
  • Step 4: Draw a circle using the circle() function.
  • Step 5: Draw lines using the line() function.
  • Step 6: Draw a rectangle using the rectangle() function.
  • Step 7: Wait for a key press using getch().

Example Program


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

main()
{

    int gd = DETECT, gm;

    initgraph(&gd, &gm, "c:\\turboc3\\bgi");

    setcolor(1);

    circle(400, 150, 30);

    setcolor(7);

    line(300, 200, 300, 450);
    line(150, 200, 50, 200);

    setcolor(15);

    rectangle(500, 100, 300, 200);

    getch();

}

Output

Draw Line Rectangle Circle Output