Untitled

 avatar
unknown
plain_text
5 months ago
848 B
2
Indexable
#include <iostream>
#include <math.h>

using namespace std;

int main()
{
    float i, x1,x2,y1,y2,dx=0,dy=0,step;
    float xinc,yinc;

    cout << " Enter starting points x1 ad y1: \n";
    cin >> x1>> y1;
    cout << " Enter destination points x2 ad y2: \n";
    cin >>  x2>> y2;

    dx=x2-x1;
    dy=y2-y1;


    step= max(dx,dy);





    xinc= dx/step;
    yinc= dy/step;

     cout<< "\n result" << endl;
     cout<< x1 << " " << y1<< endl;


     if(x1<x2 && y1<y2){

     while( x1!=x2 && y1!=y2 )
     {
         x1=(x1+xinc);
         y1=(y1+yinc);


         cout<< round(x1) << " " <<round(y1)<< endl;
     }
     }
     else
        while( x1!=x2 && y1!=y2 )
     {
         x1=(x1-xinc);
         y1=(y1-yinc);


         cout<< round(x1) << " " <<round(y1)<< endl;
     }

}
Editor is loading...
Leave a Comment