Bresenham’s Line Drawing Algorithm in C and C++

Here you will get program for bresenham’s line drawing algorithm in C and C++.

This algorithm is used in computer graphics for drawing line.

The program will work in Turbo C or Turbo C++ compiler as it uses graphics.h header file.

Make sure to change the path of BGI folder inside initgraph() function according to your system. Otherwise the program will not work.

Also Read: Bresenham’s Midpoint Circle Algorithm in C and C++

Program for Bresenham’s Line Drawing Algorithm in C

Program for Bresenham’s Line Drawing Algorithm in C++


Bresenham's Line Drawing Algorithm in C and C++

9 thoughts on “Bresenham’s Line Drawing Algorithm in C and C++

  1. Vishal

    Thank you … I did not understand this the way how it was taught in college..!!!

    1. Jadrankoo

      The answer on james question is: YES, you can compile it under CodeBlocks.. but, let’s read some facts..
      Well, first of all, CodeBlocks is just an IDE (kind of “smart” editor”) – compile process is automaticaly done calling Mingw compiler (in fact GCC) – very powerfull one…
      Graphics in this and similar examples is so called BGI graphics (Borland Graphics Interface), produced in times of DOS…
      Today, in the world of 32/64 bit operating systems and applications you have to install Code Blocks 10.05 (you can find it on: This is most simple way, because it is 32 bit system (very important: you can’t use 64 bit compiler for BGI).
      Then you have to copy file:
      1. graphics.h into folder \CodeBlocks\MinGW\include
      2. libbgi.a into folder \CodeBlocks\MinGW\lib

      And also put this in CodeBlocks Settings – Compiler settings – Linker settings, into write window (Other linker settings) (type it strictly as it is here:

      …and every code you save, writen in C (not C++) – save with extension .cpp (will not work as .c)
      Don’t forget #include …
      ..for more details see>

    1. Koichi

      It has been solved only. Just used up conio on header files and get ch() at endings since the above programmer used int function not void.

  2. abhijit

    please any one help me out in performing data communication lab manual programs of solapur university

  3. Anonymous

    You haven’t put the code for case x1 > x ?
    i.e for example if we give input where x0 is greater than x1.
    Please update the code for above case!


Leave a Reply

Your email address will not be published. Required fields are marked *