/*
Title: Digital Differntial Analyzer Line Drawing Algorithm in C
Author: Kasun Ranga Wijeweera
Email: krw19870829@gmail.com
Date: 20150401
*/
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include"D:/GP/header/grap.h"
int round(double r)
{
int x;
x=r+0.5;
return x;
}
void DDA(int x1,int y1,int x2,int y2)
{
int dx=x2-x1;
int dy=y2-y1;
int steps,k;
double xInc,yInc;
double x=x1;
double y=y1;
if(fabs(dx)>fabs(dy))
{
steps=fabs(dx);
}
else
{
steps=fabs(dy);
}
xInc=(double)dx/(double)steps;
yInc=(double)dy/(double)steps;
putpixel(round(x),round(y),15);
for(k=0;k<steps;k++)
{
x+=xInc;
y+=yInc;
putpixel(round(x),round(y),15);
}
}
void main()
{
int x1,y1,x2,y2;
ginit();
x1=100;
y1=120;
x2=200;
y2=300;
DDA(x1,y1,x2,y2);
getch();
gexit();
}

Digital Differential Analyzer Line Drawing Algorithm in C