Тема: Утворення Массиву С, із елементів массиву В, що є більші за мін знач А
Ось завдання "https://pastenow.ru/90006a622a1e1594b64356459f51c943"
Ось мій код:
#include<iostream>
#include<math.h>
#include<stdlib.h>
using namespace std;
void main() {
int * a = 0, * b = 0, * c = 0;
int sizeA, sizeB, sizeC;
int b1, b2;
float avg1=0, avg2=0;
cout << "Vvedit kilkist elementiv massuvy A: ";
cin >> sizeA;
a = new int[sizeA];
cout << "Vvedit elementu massuvy A : ";
for (int i = 0; i < sizeA; i++) {
cin >> a[i];
}
cout << "Massuv A[" << sizeA << "]={";
for (int i = 0; i < sizeA; i++) {
printf("%d ", a[i]);
}
cout << "}"<<endl;
int min = a[0];
for (int i = 0; i < sizeA; i++) {
if (a[i] < min) {
min = a[i];
}
}
cout << min << endl;
for (int i = 0; i < sizeA; i++) {
avg1 = avg1 + a[i];
}
avg1 = avg1 / sizeA;
printf("Seredne znachenna massuvy A = %.2f", avg1);
cout << endl;
int ix = 0, d = 0;
for (int i = 0; i < sizeA; i++) {
if (i == 0) {
d = fabs(avg1 - a[i]);
ix = i;
}
else if (fabs(avg1 - a[i]) < d) {
d = fabs(avg1 - a[i]);
ix = i;
}
}
cout << ix <<", e naybluzcum do avg massumy A";
cout << endl;
//***********************************************************************************
cout << endl;
cout << "Vkazit rozmir massuvy B: ";
cin >> sizeB;
b = new int[sizeB];
cout << endl;
cout << "Vkazit diapazon elementiv massuvy B: ";
cin >> b1 >> b2;
for (int i = 0; i < sizeB; i++) {
b[i] = rand() % (b2 - b1 + 1) + b1;
}
cout << "Zhenerovanuy massuv B[" << sizeB << "]={";
for (int i = 0; i < sizeB; i++) {
printf("%d ", b[i]);
}
cout << "}" << endl;
for (int i = 0; i < sizeA; i++) {
avg2 = avg2 + b[i];
}
avg2 = avg2 / sizeB;
printf("Seredne znachenna massuvy B = %.2f", avg2);
cout << endl;
int ix1 = 0, d1 = 0;
for (int i = 0; i < sizeB; i++) {
if (i == 0) {
d = fabs(avg2 - b[i]);
ix1 = i;
}
else if (fabs(avg2 - b[i]) < d1) {
d1 = fabs(avg2 - b[i]);
ix1 = i;
}
}
cout << ix1 << ", e naybluzcum do avg massumy B";
cout << endl;
//***********************************************************************************
}