Begin16. Find the distance between two points with given coordinates \(x_1\) and \(x_2\) on the numerical axis: \(|x_2 - x_1|\).

Solution in Python 3:

import random

x1 = random.randrange(-10,10)
x2 = random.randrange(-10,10)
print("x1: ", x1)
print("x2: ", x2)
print("Distance: ", abs(x2-x1))

Solution in C++:

#include <iostream>
#include <cmath>
using namespace std;
int main(){
double x1, x2, d;
cout << "Enter the coordinate of x1: ";
cin >> x1;
cout << "Enter the coordinate of x2: ";
cin >> x2;
d = abs(x1-x2);
cout << "Distance: " << d;
return 0;
}