You are on page 1of 2

#include<stdio.

h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
#include<math.h>

float sign(float o)
{
float g;
if(g>0)
return 1;
else
return -1;
}

void main()
{
int x1,y1,x2,y2,xdist,ydist,i;
float length,x,y,xinc,yinc,xfloor,yfloor;
int gd = DETECT, gm;
initgraph(&gd,&gm,"C:\\TURBOC3\\BGI");
clrscr();

printf("Enter the inital coordinates: ");


scanf("%d%d",&x1,&y1);
printf("\nEnter the terminating coordinates: ");
scanf("%d%d",&x2,&y2);

//Finding length of line//


xdist=abs(x2-x1);
ydist=abs(y2-y1);
if(xdist>ydist)
length=xdist;
else
length=ydist;

//Finding increments//
xinc=xdist/length;
yinc=ydist/length;

//Rounding off the values//


x=x1+(0.5*sign(xinc));
y=y1+(0.5*sign(yinc));
clrscr();

//Main loop
for(i=1;i<=length;i++)
{
x=x+xinc;
y=y+yinc;
xfloor=floor(x);
yfloor=floor(y);

putpixel(xfloor,yfloor,BLUE);
}
getch();
closegraph();
}

You might also like