Begin10. Two non-zero numbers are given. Find the sum, difference, product and quotient of their squares.

Solution in Python 3:

import random

a = random.randrange(1,10)
b = random.randrange(1,10)
print("a = ", a)
print("b = ", b)
a2 = a**2
b2 = b**2
print("Square of a = ", a2)
print("Square of b = ", b2)
print("Sum of the squares: ", a2+b2)
print("Difference of the squares: ", abs(a2-b2))
print("Product of squares: ", a2*b2)
print("Quotient of squares: ", a2/b2)

Solution in C++:

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