Proc 3. Описать процедуру Mean(X, Y, AMean, GMean), вычисляющую среднее арифметическое AMean = (X +Y )/2 и среднее геометрическое \(GMean = \sqrt{X \cdot Y}\) двух положительных чисел X и Y (X и Y — входные, AMean и GMean — выходные параметры вещественного типа). С помощью этой процедуры найти среднее арифметическое и среднее геометрическое для пар (A, B), (A, C), (A, D), если даны A, B, C, D.

Решение на Python 3

import random
import math

def Mean(X,Y,Result):
Result['AMean'] = (X + Y) / 2
Result['GMean'] = math.sqrt(X * Y)
return

R = {'AMean' : None, 'GMean' : None}
#A = random.uniform(-10,10)
A = random.randrange(0,10)
B = random.randrange(0,10)
C = random.randrange(0,10)
D = random.randrange(0,10)

print('A = ', A)
print('B = ', B)
print('C = ', C)
print('D = ', D)

print("(A,B)")
Mean(A,B,R)
print('AMean = ', R['AMean'])
print('GMean = ', R['GMean'])

print("(A,C)")
Mean(A,C,R)
print('AMean = ', R['AMean'])
print('GMean = ', R['GMean'])

print("(A,D)")
Mean(A,D,R)
print('AMean = ', R['AMean'])
print('GMean = ', R['GMean'])

Решение на C++

#include <bits/stdc++.h>
using namespace std;

void Mean(double X, double Y,
double &AMean, double &GMean) {
AMean = (X + Y) / 2.0;
GMean = sqrt(X * Y);
return;
}

int main() {
srand((int)time(0));
double a, b, c, d;
double AMean, GMean;

a = rand() % 20 + 1;
b = rand() % 20 + 1;
c = rand() % 20 + 1;
d = rand() % 20 + 1;
cout << "A = " << a << " : ";
cout << "B = " << b << " : ";
cout << "C = " << c << " : ";
cout << "D = " << d << endl;

Mean(a,b,AMean,GMean);
cout << endl <<"(A,B)" << endl;
cout << "AMean = " << AMean << " : ";
cout << "GMean = " << GMean << endl;

Mean(a,c,AMean,GMean);
cout << endl <<"(A,C)" << endl;
cout << "AMean = " << AMean << " : ";
cout << "GMean = " << GMean << endl;

Mean(a,d,AMean,GMean);
cout << endl <<"(A,D)" << endl;
cout << "AMean = " << AMean << " : ";
cout << "GMean = " << GMean << endl;

return 0;
}