Решение на c++:
#include <iostream>
#include <ctime>
int main()
{
int N, i, a, b, k1 = 0, k2 = 0, s1 = 0, s2 = 0;
int A[10000];
std::cin >> a >> b >> N;
srand(time(0));
for (i = 0; i < N; i++)
A[i] = rand()%(b-a+1)+a;
if (A[i] < 50)
k1++;
s1 += A[i];
}
else
k2++;
s2 += A[i];
std::cout << A[i] << " ";
std::cout << std::endl << ((k1 == 0) ? 0 : (s1*1./k1)) << " ";
std::cout << ((k2 == 0) ? 0 : (s2 * 1. / k2)) << " ";
return 0;
#include <iostream>
using namespace std;
int main(){
srand(time(NULL));
int n;
cout << "Vvedite N << endl;
cin >> n;
int arr[n];
int a,b;
cout << "Vvedite diapozon A-B cherez probel" << endl;
cin >> a >> b;
for (int i=0; i<n; i++) a[i]=rand()%b+a;
int s50 = 0;
int ss50 = 0;
int s = 0;
int ss = 0;
for (int i=0; i<n; i++) {
if (a[i]<50) {
s50+=a[i];
ss50++;
} else {
s+=a[i];
ss++;
}
}
cout << "Srednee arifmeticheskoe chisel menshe 50 ravno " << s50/ss50 << endl;
cout << "Srednee arifmeticheskoe chisel ostalnix elementov ravno " << s/ss;
return 0;
}
Решение на c++:
#include <iostream>
#include <ctime>
int main()
{
int N, i, a, b, k1 = 0, k2 = 0, s1 = 0, s2 = 0;
int A[10000];
std::cin >> a >> b >> N;
srand(time(0));
for (i = 0; i < N; i++)
{
A[i] = rand()%(b-a+1)+a;
if (A[i] < 50)
{
k1++;
s1 += A[i];
}
else
{
k2++;
s2 += A[i];
}
std::cout << A[i] << " ";
}
std::cout << std::endl << ((k1 == 0) ? 0 : (s1*1./k1)) << " ";
std::cout << ((k2 == 0) ? 0 : (s2 * 1. / k2)) << " ";
return 0;
}