Program:
#include<iostream.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
#include<math.h>
void main()
{
clrscr();
float xnew,ynew,x1,y1,x2,y2,dx,dy,e;
int i,gd=DETECT,gm;
cout<<"Enter the value of x1 and y1: ";
cin>>x1>>y1;
cout<<"Enter the value of x2 and y1: ";
cin>>x2>>y2;
initgraph(&gd,&gm,"c:\\tc\\bgi");
dx=abs(x2-x1);
dy=abs(y2-y1);
xnew=x1;
ynew=y1;
e=2*dy-dx;
i=1;
do
{
putpixel(xnew,ynew,BLUE);
while(e>=0)
{
ynew=ynew+1;
e=e-2*dx;
}
xnew=xnew+1;
e=e+2*dy;
i=i+1;
}
while(i<=dx);
getch();
closegraph();
}
No comments:
Post a Comment