Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

#include<stdio.

h>
#include<conio.h>
#include<math.h>
#include<graphics.h>
void main()
{
int x1,x2,y1,y2,x3,y3,p,k=0;
int graphdriver=DETECT,graphmode=0;
initgraph(&graphdriver,&graphmode,"c:\\tc\\bgi");
printf("enter the first points");
scanf("%d%d",&x1,&y1);
putpixel(x1,y1,12);
printf("enter the second points");
scanf("%d%d",&x2,&y2);
x3=abs(x2-x1);
y3=abs(y2-y1);
p=(2*x3-y3);
while(k<y3)
{
if(p<=0)
{
y1=y1+1;
p=(p*2*x3);
}
else
{
x1=x1+1;
y1=y1+1;
p=(p*2*x3-2*y3);
}
putpixel(x1,y1,12);
//printf("\n(%d%d)",x1,y1);
k++;
}
getch();
}

You might also like