Advertisement
Pappu19

dda

Sep 28th, 2021
720
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.82 KB | None | 0 0
  1.  
  2. #include<stdio.h>
  3. #include<math.h>
  4. #include<conio.h>
  5. #include<graphics.h>
  6. #include<time.h>
  7. int main()
  8. {
  9.     int gd=DETECT,gm;
  10.     initgraph (&gd,&gm,"");
  11.     float x, y, x1, y1, x2, y2, dx, dy, step;
  12.     int i;
  13.  
  14.     printf("Enter x1 and y1:\n");
  15.     scanf ("%f %f", &x1, &y1);
  16.  
  17.     printf("Enter x2 and y2:\n");
  18.     scanf ("%f %f", &x2, &y2);
  19.  
  20.     dx = (x2 - x1);
  21.     dy = (y2 - y1);
  22.  
  23.     if(dx >= dy)
  24.     {
  25.         step = dx;
  26.     }
  27.  
  28.     else
  29.         step = dy;
  30.  
  31.     dx = dx/step;
  32.     dy = dy/step;
  33.  
  34.     x = x1;
  35.     y = y1;
  36.  
  37.  
  38.  printf("Values of x and y:\n ");
  39.  
  40.     for(i = 1;i <= step; i++)
  41.     {
  42.         x = x + dx;
  43.         y = y + dy;
  44.  
  45.         printf("%f %f \n", round(x) , round(y));
  46.         putpixel(round(x) , round(y),WHITE);
  47.         delay(10);
  48.     }
  49.      getch();
  50.      closegraph();
  51. }
  52.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement