#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void ddaline(int x1,int y1,int x2,int y2);
void main()
{
int gd,gm;
gd=gm=DETECT;
initgraph(&gd,&gm,"C:\\TURBOC3\\BGI");
ddaline(50,200,100,100);
ddaline(100,100,150,200);
ddaline(100,100,350,100);
ddaline(350,100,400,200);
ddaline(50,200,400,200);
ddaline(50,200,50,400);
ddaline(150,200,150,400);
ddaline(400,200,400,400);
ddaline(50,400,400,400);
getch();
closegraph();
}
void ddaline(int x1,int y1,int x2,int y2)
{
int Sx,Sy,Steps,i;
float xincr,yincr,x,y;
Sx=x2-x1;
Sy=y2-y1;
if(Sx>=Sy)
Steps=Sx;
else
Steps=Sy;
xincr=Sx/Steps;
yincr=Sy/Steps;
x=x1;
y=y1;
for(i=1;i<=Steps;i++)
{
putpixel(x+0.5,y+0.5,WHITE);
x=x+xincr;
y+=yincr;
}
getch();
}