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 | #include<stdio.h> #include<conio.h> #include<graphics.h> #include<math.h> void main() { int Xs,Ys,Xe,Ye,dx,dy; float X,Y,p; int gd=DETECT,gm ; initgraph(&gd,&gm,"C:\\tc\\bgi"); printf ("Enter the value of (Xs , Xs ) & (Xe , Ye)\n"); scanf ("%d%d%d%d", &Xs ,&Ys , &Xe , &Ye); dy=Ye-Ys; dx=Xe-Xs; p=(2*dy)-dx; X=Xs; Y=Ys; cleardevice( ); putpixel(X,Y,YELLOW); while(X!=Xe && Y!=Ye) { if(p<1) { X=X+1; p=p+(2*dy); putpixel (X,Y,RED); } else { X=X+1; Y=Y+1; p=p+(2*dy)-(2*dx); putpixel(X,Y,GREEN); } } getch ( ); closegraph ( ); } |