DDA Line Drawing Algorithm C Program


Let us understand what is DDA algorithm in computer graphics and then let us see how to implement DDA line drawing algorithm in C programming using different methods.

What is DDA Line Algorithm?

DDA is an abbreviation for Digital Differential Analyzer. It is primarily used to find the interpolation over an interval between the initial and end coordinates.


It is an incremental scan-conversion line drawing algorithm. The calculations performed at every increment is based on the previous increment.

To draw any line in computer graphics, you need two coordinates on a 2-dimensional planar surface. Every line will have the start point (X0, Y0) and end point (X1, Y1).

For drawing a DDA line, we cannot directly connect the start and end points. We have to calculate intermediate point’s coordinate. Then, we have to insert an increment for each intermediate point on the line.

In this algorithm, we need to use floating-point arithmetic and it can use multiplication and division operations. This algorithm is a faster method for calculating the positions of the pixels.

There are, however, a lot of disadvantages with this line drawing algorithm. It is not very efficient when it comes to optimisation. It is not accurate as compared to other line drawing algorithms.

The c program for DDA line drawing algorithm rounds off the line coordinates to an integer which is an approximation to the expected line. However, the round operations in the algorithm are too inefficient.

There are several other line drawing algorithms that are much more efficient and accurate than DDA algorithm such as Bresenham line drawing algorithm.

DDA Line Generation Algorithm


IMPORTANT: x1 != x2 and y1 != y2

If you face any issues while compiling this line drawing graphics program, you may have to install graphics.h in your operating system.

Note: This C program for DDA line generation algorithm is compiled with Turbo C compiler on Microsoft Windows 10 operating system.


Method 1: C Program To Implement DDA Line Drawing Algorithm

Method 2: DDA line drawing algorithm in C Programming using Function


Enter Initial Line Coordinates
Enter the value of x1:      50
Enter the value of y1:      70
Enter Final Line Coordinates
Enter the value of x2:      80
Enter the value of y2:      120
Enter delay time:              4

Implement DDA Line Drawing Algorithm in C Programming using Functions with Output and Explanation

Let us discuss more on this DDA line drawing algorithm in C programming in the comment section below.

Do let us know if you have any doubts or have any information to share. For information, check Wikipedia.

2 thoughts on “DDA Line Drawing Algorithm C Program

  1. Mahesh Sharma

    Why don’t you guys use OpenGL for all these graphics line drawing codes? Its much better and advanced than graphics.h or sdl.h.


Let's Discuss