#include
#include
#include
#include
using namespace std;
typedef unsigned short int USI;
int* fillArray(string name, int s);
int maxArray(int[], int s);
bool isPrime(int);
void deleteAllEqualTo(int[], int s, int value);
float averageOfPositive(int[], int s);
void printArray(int[], int s);
bool sortByDescAbs(int i, int j) {
return abs(i) > abs(j);
}
int main() {
setlocale(LC_ALL, "Russian");
USI n;
cout << "n = "; <br> cin >> n;
int* z = fillArray("z", n);
int max = maxArray(z, n);
if ( isPrime(max) ) {
deleteAllEqualTo(z, n, max);
}
float avg = averageOfPositive(z, n);
cout << "среднее: " << avg << '\n';<br> sort(z, z + n, sortByDescAbs);
cout << "z[" << n << "]: ";<br> printArray(z, n);
return 0;
}
int* fillArray(string name, int s) {
int array[s];
for (int i = 0; i < s; i++) {
cout << name << "[" << i << "] = ";<br> cin >> array[i];
}
return array;
}
int maxArray(int a[], int s) {
int max = a[0];
for (int i = 1; i < s; i++) {
if (a[i] > max) max = a[i];
}
return max;
}
bool isPrime(int n) {
if (n < 2) return false;
if (n == 2) return true;
if (n % 2 == 0) return false;
for (int i = 3; (i*i) <= n; i += 2) {<br> if (n % i == 0 ) return false;
}
return true;
}
void deleteAllEqualTo(int a[], int s, int value) {
for (int i = 0; i < s; i++) {
if (a[i] == value) a[i] = 0;
}
}
float averageOfPositive(int a[], int s) {
unsigned int sum = 0,
count = 0;
for (int i = 0; i < s; i++) {
if (a[i] > 0) {
sum += a[i];
count++;
}
}
return (sum / count);
}
void printArray(int a[], int s) {
for (int i = 0; i < s; i++) {
cout << a[i] << ' ';<br> }
}