Заданы два массива А(5) и В(5). Подсчитать в них количество элементов, меньших значения t и первым на печать вывести массив, имеющий наибольшее их количество на языке с++
int main() { int A[5] = {2, 5, 7, 1, 4}; int B[5] = {3, 6, 8, 2, 9}; int t = 5;
int countA = 0; int countB = 0; for (int i = 0; i < 5; i++) { if (A[i] < t) { countA++; } if (B[i] < t) { countB++; } } cout << "Array A has " << countA << " elements less than " << t << endl; cout << "Array B has " << countB << " elements less than " << t << endl; if (countA > countB) { cout << "Array A has the most elements less than " << t << endl; } else if (countB > countA) { cout << "Array B has the most elements less than " << t << endl; } else { cout << "Both arrays have the same number of elements less than " << t << endl; } return 0;
using namespace std;
int main() {
int countA = 0;int A[5] = {2, 5, 7, 1, 4};
int B[5] = {3, 6, 8, 2, 9};
int t = 5;
int countB = 0;
for (int i = 0; i < 5; i++) {
if (A[i] < t) {
countA++;
}
if (B[i] < t) {
countB++;
}
}
cout << "Array A has " << countA << " elements less than " << t << endl;
cout << "Array B has " << countB << " elements less than " << t << endl;
if (countA > countB) {
cout << "Array A has the most elements less than " << t << endl;
} else if (countB > countA) {
cout << "Array B has the most elements less than " << t << endl;
} else {
cout << "Both arrays have the same number of elements less than " << t << endl;
}
return 0;
}