Begin11. Two non-zero numbers are given. Find the sum, difference, product and quotient of their absolute values (modulus).

Solution in Python 3:

import random

a = random.uniform(-100,100)
b = random.uniform(-100,100)
print("a = ", a)
print("b = ", b)
abs_a = abs(a)
abs_b = abs(b)
print("Absolute value of a = ", abs_a)
print("Absolute values of b = ", abs_b)
print("Sum of absolute values: ", abs_a + abs_b)
print("Difference of absolute values: ", abs(abs_a - abs_b))
print("Product of absolute values: ", abs_a * abs_b)
print("Quotient of absolute values: ", abs_a / abs_b)

Solution in C++:

#include <iostream>
#include <cmath>
using namespace std;
int main(){
double a,b,a2,b2,s,r,p,c;
cout << "Enter the number a: ";
cin >> a;
cout << "Enter the number b: ";
cin >> b;
a2 = abs(a);
b2 = abs(b);
s = a2+b2;
r = abs(a2-b2);
p = a2*b2;
c = a2/b2;
cout << "Sum of absolute values: " << s << endl;
cout << "Difference of absolute values: " << r << endl;
cout << "Product of absolute values: " << p << endl;
cout << "Quotient of absolute values: " << c;
return 0;
}