Begin18. Three points \(A, B, C\) are given on the number axis. The point \(C\) is located between the points \(A\) and \(B\). Find the product of the lengths of the segments \(AC\) and \(BC\).

Solution in Python 3:

import random

A,C,B = sorted(random.sample(range(-10, 10), 3))

print("A: ", A)
print("B: ", B)
print("C: ", C)
AC = abs(A-C)
BC = abs(B-C)
AC_BC = AC * BC
print("AC: ", AC)
print("BC: ", BC)
print("AC * BC: ", AC_BC)

Solution in C++:

#include <iostream>
#include <cmath>
using namespace std;
int main(){
double a,b,c,ac,bc,p;
cout << "Enter the coordinate of a: ";
cin >> a;
cout << "Enter the coordinate of b: ";
cin >> b;
cout << "Enter the coordinate of c: ";
cin >> c;
ac = abs(a-c);
bc = abs(b-c);
p = ac*bc;
cout << "Length of AC: " << ac << endl;
cout << "Length of BC: " << bc << endl;
cout << "Product of the lengths of AC and BC: " << p;
return 0;
}