#include<stdio.h>
#include<math.h>
#include<conio.h>
#include<graphics.h>
void main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"c:\\tc\\bgi");
void line_dda(int,int,int,int);
int xa,xb,ya,yb;
printf("Enter the co-ordinates of point A(x1,y1) :");
scanf("%d%d",&xa,&ya);
printf("Enter the co-ordinates of point B(x2,y2) :");
scanf("%d%d",&xb,&yb);
cleardevice();
line_dda(xa,ya,xb,yb);
getch();
closegraph();
}
void line_dda(int xa,int ya,int xb,int yb)
{
int Dx=xb-xa,Dy=yb-ya,steps,k;
float xin,yin,X=xa,Y=ya;
if(abs(Dx)>abs(Dy))
steps=abs(Dx);
else
steps=abs(Dy);
xin=Dx/(float)steps;
yin=Dy/(float)steps;
putpixel(X,Y,6);
for(k=0;k<steps;k++)
{
X=X+xin;
Y=Y+yin;
putpixel(X,Y,6);
}
}
OUTPUT
No comments:
Post a Comment