#include <iostream> #include <stdlib.h> using namespace std;
int main() { const int n = 10; int a[n]; double s=0; int k=0;
srand(time(0)); for (int i = 0; i < n; i++) { a[i]=-20 + (101.0 / RAND_MAX) * rand(); cout << a[i] << " "; } cout <<"\n";
for (int i = 0; i <= n; i++){ s = s+a[i]; } s = s/n; cout << "Среднее = " << s <<"\n"; for (int i = 0; i <= n; i++){ if (a[i]>s) k++; } cout << "k = " << k <<"\n";
#include <stdlib.h>
using namespace std;
int main() {
const int n = 10;
int a[n];
double s=0;
int k=0;
srand(time(0));
for (int i = 0; i < n; i++) {
a[i]=-20 + (101.0 / RAND_MAX) * rand();
cout << a[i] << " ";
}
cout <<"\n";
for (int i = 0; i <= n; i++){
s = s+a[i];
}
s = s/n;
cout << "Среднее = " << s <<"\n";
for (int i = 0; i <= n; i++){
if (a[i]>s) k++;
}
cout << "k = " << k <<"\n";
return 0;
}
Пример:
-18 80 77 66 74 44 62 78 45 0
Среднее = 50.9
k = 6