Advertisement
AmidamaruZXC

Untitled

Jan 24th, 2020
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.09 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     double x1, x2, x3, v1, v2, v3;
  9.     double time12, time23, time13;
  10.     cout << "Input x1: ";
  11.     cin >> x1;
  12.     cout << "Input speed of x1: ";
  13.     cin >> v1;
  14.     cout << "Input x2: ";
  15.     cin >> x2;
  16.     cout << "Input speed of x2: ";
  17.     cin >> v2;
  18.     cout << "Input x3: ";
  19.     cin >> x3;
  20.     cout << "Input speed of x3: ";
  21.     cin >> v3;
  22.     if (x1 >= x2)
  23.         time12 = (x1 - x2) / (v2 - v1);
  24.     else
  25.         time12 = (x2 - x1) / (v1 - v2);
  26.     if (x1 >= x3)
  27.         time13 = (x1 - x3) / (v3 - v1);
  28.     else
  29.         time13 = (x3 - x1) / (v1 - v3);
  30.     if (x2 >= x3)
  31.         time23 = (x2 - x3) / (v3 - v2);
  32.     else
  33.         time23 = (x3 - x2) / (v2 - v3);
  34.     if (time12 >= 0)
  35.         cout << "Points x1 and x2 intersect at time: " << time12 << endl;
  36.     else
  37.         cout << "Points x1 and x2 do not intersect!\n";
  38.     if (time13 >= 0)
  39.         cout << "Points x1 and x3 intersect at time: " << time13 << endl;
  40.     else
  41.         cout << "Points x1 and x3 do not intersect!\n";
  42.     if (time23 >= 0)
  43.         cout << "Points x2 and x3 intersect at time: " << time23 << endl;
  44.     else
  45.         cout << "Points x2 and x3 do not intersect!\n";
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement