You are here

Line function in c

line function is used to draw a line from a point(x1,y1) to point(x2,y2) i.e. (x1,y1) and (x2,y2) are end points of the line.The code given below draws a line.

Declaration: void line(int x1, int y1, int x2, int y2);

C programming code for line

  1. #include <graphics.h>
  2. #include <conio.h>
  3.  
  4. main()
  5. {
  6.    int gd = DETECT, gm;
  7.  
  8.    initgraph(&gd, &gm, "C:\\TC\\BGI");
  9.  
  10.    line(100, 100, 200, 200);
  11.  
  12.    getch();
  13.    closegraph();
  14.    return 0;
  15. }

Above program draws a line from (100, 100) to (200, 200).