How To Use line Function In C Or C++ Graphics

line function in c

Introduction :

In this article I will show you how to draw line from one point to another point by C or C++ using line function. line is built-in function in graphics header

Declaration :

line(int x1,int y1, int x2,int y2);

How to use :

For use this function you have to install turboc++. In this example I will show you how to draw a line using C or C++ programing. The following code draws a line. Just create a c or c++ file in turboc++ and copy paste following code in it.

/*Developed by Puskar Jasu*/
#include <graphics.h>
#include <conio.h>
main()
{
    int x1, x2, y1, y2;
    int graphic_driver = DETECT, graphic_mode;
    initgraph(&graphic_driver, &graphic_mode, "//turboc3/bgi");
    setcolor(4);
    x1 = 100;
    x2 = 400;
    y1 = 100;
    y2 = 300;
    line(x1, y1, x2, y2);
    getch();
    closegraph();
    return 0;
}

Output :

You can see the output of above code.

line output

Conclusion :

In this article I show you how you draw line in C graphics by turboc++. Thanks for visit my site.

You can see my following project :

You can see my following program :

Scroll to Top