Begin17. Three points \(A, B, C\) are given on the number axis. Find the lengths of the segments \(AC\) and \(BC\) and their sum.

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
AB = abs(A-B)
print("AC: ", AC)
print("BC: ", BC)
print("AC + BC: ", AC_BC)
print("AB: ", AB)

Solution in C++:

#include <iostream>
#include <cmath>
using namespace std;
int main(){
double a,b,c,ac,bc,s;
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);
s = ac+bc;
cout << "Length of AC: " << ac << endl;
cout << "Length of BC: " << bc << endl;
cout << "Sum of the lengths of AC and BC: " << s;
return 0;
}