program Geom;
program Test_nn;
{$APPTYPE CONSOLE}
{$R *.res}
uses
Math;
var
a: array of Extended;
n, i, c: Integer;
x: Extended;
begin
Write ('Размерность массива = ');
ReadLn (n);
SetLength (a, n);
Randomize;
for i := Low (a) to High (a) do begin
a [i] := (Random (2001) - 1000) / 1000;
Write (a [i] :7 :3);
end;
x := 1;
c := 1;
WriteLn;
if a [i] > 0 then begin
x := x * a [i];
Inc (c);
WriteLn ('Среднее геометрическое = ', Power (x, 1/c) :20 :15);
ReadLn;
end.
#include <iostream>
#include <ctime>
#include <algorithm>
using namespace std;
int* input_arr_auto(int* arr, int n) {
for (int i = 0; i < n; i++) {
arr[i] = rand() % 100;
}
return arr;
void print_array(int* arr, int n) {
cout << endl;
cout << arr[i] << "\t";
int* input_arr(int* arr, int n) {
cout << "Введите элементы массива по одному, или используйте другую функцию для автозаполнения";
cin >> arr[i];
int third_largest(int* arr, int n) {
int first=arr[0], second=arr[0], third=arr[0];
if (n < 3) {
return -1;
for (int i = 0; i < n; i++)
{
if (arr[i] > first)
third = second;
second = first;
first = arr[i];
else if (arr[i] > second)
second = arr[i];
else if (arr[i] > third)
third = arr[i];
return third;
int main() {
srand(time(NULL));
setlocale(LC_ALL, "Russian");
int n, third_elem;
cout << "Введите размерность N: ";
cin >> n;
int* arr = new int[n];
arr = input_arr_auto(arr, n);
print_array(arr, n);
third_elem = third_largest(arr, n);
if (third_elem == -1) {
cout << "Недостаточно элементов массива";
if (arr[i] > third_elem) {
arr[i] = third_elem;
program Geom;
program Test_nn;
{$APPTYPE CONSOLE}
{$R *.res}
uses
Math;
var
a: array of Extended;
n, i, c: Integer;
x: Extended;
begin
Write ('Размерность массива = ');
ReadLn (n);
SetLength (a, n);
Randomize;
for i := Low (a) to High (a) do begin
a [i] := (Random (2001) - 1000) / 1000;
Write (a [i] :7 :3);
end;
x := 1;
c := 1;
WriteLn;
for i := Low (a) to High (a) do begin
if a [i] > 0 then begin
Write (a [i] :7 :3);
x := x * a [i];
Inc (c);
end;
end;
WriteLn;
WriteLn ('Среднее геометрическое = ', Power (x, 1/c) :20 :15);
ReadLn;
end.
#include <iostream>
#include <ctime>
#include <algorithm>
using namespace std;
int* input_arr_auto(int* arr, int n) {
for (int i = 0; i < n; i++) {
arr[i] = rand() % 100;
}
return arr;
}
void print_array(int* arr, int n) {
cout << endl;
for (int i = 0; i < n; i++) {
cout << arr[i] << "\t";
}
}
int* input_arr(int* arr, int n) {
cout << "Введите элементы массива по одному, или используйте другую функцию для автозаполнения";
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
return arr;
}
int third_largest(int* arr, int n) {
int first=arr[0], second=arr[0], third=arr[0];
if (n < 3) {
return -1;
}
for (int i = 0; i < n; i++)
{
if (arr[i] > first)
{
third = second;
second = first;
first = arr[i];
}
else if (arr[i] > second)
{
third = second;
second = arr[i];
}
else if (arr[i] > third)
third = arr[i];
}
return third;
}
int main() {
srand(time(NULL));
setlocale(LC_ALL, "Russian");
int n, third_elem;
cout << "Введите размерность N: ";
cin >> n;
int* arr = new int[n];
arr = input_arr_auto(arr, n);
print_array(arr, n);
third_elem = third_largest(arr, n);
if (third_elem == -1) {
cout << "Недостаточно элементов массива";
}
for (int i = 0; i < n; i++) {
if (arr[i] > third_elem) {
arr[i] = third_elem;
}
}
print_array(arr, n);
}