1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
#include<graphics.h> #include<iostream.h> #include<dos.h> #include<math.h> #include<conio.h> void main() { int gd=DETECT,gm; int x1,x2,y1,y2; int i,flag,d; clrscr(); cout<<"Enter value of (x1,y1)= "; cin>>x1>>y1; cout<<"Enter value of (x2,y2)= "; cin>>x2>>y2; initgraph(&gd,&gm,"c:\\tc\\bgi"); int dx,dy; dx=abs(x2-x1); dy=abs(y2-y1); int x,y,t,s1,s2; x=x1; y=y1; if((x2-x1)>0) s1=1; else s1=-1; if((y2-y1)>0) s2=1; else s2=-1; if(dy>dx) { t=dx; dx=dy; dy=t; flag=1; } else flag=0; d=2*dy-dx; outtextxy(x1,y1,"(x1,y1)"); outtextxy(x2,y2,"(x2,y2)"); i=1; a: putpixel(x,y,3); delay(40); while(d>=0) { if (flag==1) x=x+s1; else y=y+s2; d=d-2*dx; } if (flag==1) y=y+s2; else x=x+s1; d=d+2*dy; i++; if(i<=dx) goto a; getch(); closegraph(); } |

## Recent Comments