#include<conio.h>
#include<stdio.h>
#include<graphics.h>
void main()
{
int gd=DETECT, gm, i;
float dx, dy, a, b, c, d, m, t;
clrscr();
initgraph(&gd,&gm,"c:\\tc\\bgi");
printf("enter starting and ending point : ");
scanf("%f %f %f %f",&a,&b,&c,&d);
if(a>c)
{
t=a;
a=c;
c=t;
t=b;
b=d;
d=t;
}
dx=c-a;
dy=d-b;
m=dy/dx;
putpixel(a,b,100);
if(abs(m)<=1)
{
for(i=0; i<dx; i++)
{
a=a+1;
b=b+m;
putpixel(a,b,100);
}
}
if(abs(m)>1)
{
for(i=0; i<dx; i++)
{
a=a+(1/m);
b=b+1;
putpixel(a,b,100);
}
}
getch();
closegraph();
}
No comments:
Post a Comment