DDA Line Drawing Algorithm in C and C++

Here you will learn about dda line drawing algorithm in C and C++.

In Computer Graphics the first basic line drawing algorithm is Digital Differential Analyzer (DDA) Algorithm.

A line connects two points. It is a basic element in graphics. To draw a line, you need two points between which you can draw a line.

Also Read: Bresenham’s Line Drawing Algorithm in C and C++

Digital Differential Analyzer (DDA) Algorithm

Step 1: Read the input of the 2 end points of the line as (x1, y1) & (x2, y2) such that x1 != x2 and y1 != y2

Step 2: Calculate dx = x2 – x1 and dy = y2 – y1

Step 3:





Step 4: xin = dx / step & yin = dy / step

Step 5: x = x1 + 0.5 & y = y1 + 0.5

Step 6: 

for(k = 0; k < step; k++)


x = x + xin

y = y + yin

putpixel(x, y)


Program for DDA Line Drawing Algorithm in C


DDA Line Drawing Algorithm in C and C++

Program for DDA Line Drawing Algorithm in C++

Comment below if you have any doubts related above algorithm.

3 thoughts on “DDA Line Drawing Algorithm in C and C++

  1. vishalmadheshiya

    No such file or directory
    compilation terminated.

    this error is encountered while compilation of the above written program

  2. Hassan javed

    all programs are awesome, Thanks for such a nice blog, where can I get all the commands used in graphics.h ??? I want to know, making circle, and the arguments of circle, what is first one? Or x and y are used to give it postiion, you things like that,


Leave a Reply

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