Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- using namespace std;
- int main()
- {
- double x1, x2, x3, v1, v2, v3;
- double time12, time23, time13;
- cout << "Input x1: ";
- cin >> x1;
- cout << "Input speed of x1: ";
- cin >> v1;
- cout << "Input x2: ";
- cin >> x2;
- cout << "Input speed of x2: ";
- cin >> v2;
- cout << "Input x3: ";
- cin >> x3;
- cout << "Input speed of x3: ";
- cin >> v3;
- if (x1 >= x2)
- time12 = (x1 - x2) / (v2 - v1);
- else
- time12 = (x2 - x1) / (v1 - v2);
- if (x1 >= x3)
- time13 = (x1 - x3) / (v3 - v1);
- else
- time13 = (x3 - x1) / (v1 - v3);
- if (x2 >= x3)
- time23 = (x2 - x3) / (v3 - v2);
- else
- time23 = (x3 - x2) / (v2 - v3);
- if (time12 >= 0)
- cout << "Points x1 and x2 intersect at time: " << time12 << endl;
- else
- cout << "Points x1 and x2 do not intersect!\n";
- if (time13 >= 0)
- cout << "Points x1 and x3 intersect at time: " << time13 << endl;
- else
- cout << "Points x1 and x3 do not intersect!\n";
- if (time23 >= 0)
- cout << "Points x2 and x3 intersect at time: " << time23 << endl;
- else
- cout << "Points x2 and x3 do not intersect!\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement