double findMin(double arr[], int size)
{
// Find the minimum element in the array
double min = arr[0];
for (int i = 1; i < size; i++)
min = min(min, arr);
return min;
}
double findMax(double arr[], int size)
{
// Find the maximum element in the array
double max = arr[0];
for (int i = 1; i < size; i++)
max = max(max, arr);
return max;
}
double mean(double arr[], int size, double min, double max)
{
// Find the arithmetic mean of the elements between min and max in the array
double sum = 0;
int count = 0;
for (int i = 0; i < size; i++)
{
if (arr > min && arr < max)
{
sum += arr;
count++;
}
}
return (count == 0) ? 0 : sum / count;
}
int main()
{
int size;
cout << "Enter the size of the array: ";
cin >> size;
cout << "Enter the elements of the array: ";
for (int i = 0; i < size; i++)
cin >> arr;
double min = findMin(arr, size);
double max = findMax(arr, size);
double m = mean(arr, size, min, max);
cout << "Minimum element: " << min << endl;
cout << "Maximum element: " << max << endl;
cout << "Arithmetic mean: " << m << endl;
1) Создается функция void в которой определяются int min, int max, int avg.
2) В этой функции прописывается логика
Логику такой сложной программы проще писать вложенными циклами (for i++ внутри которого for j++ (важно чтобы эти переменные отличались). Путём перебора и сравнения каждого можно получить наименьшее и наиболее. Среднее арифм. считать учат ещё в начальной школе, пояснять не буду.
3) В главной функции int main
Задается массив, можно сразу ограничить его до 200 элементов или сделать динамический (по опыту правильно написать с 1 раза динамический массив могут единицы людей). Запись в массив делается в цикле. Далее идёт обращение к функции void. покажу на примере: #include "stdafx.h"
#include
using namespace std;
// объявление функции нахождения n!
void faktorial(int numb)// заголовок функции
{
int rezult = 1; // инициализируем переменную rezult значением 1
for (int i = 1; i