cout << "Enter 12 integers: "; for (int i = 0; i < 12; i++) { cin >> arr[i]; } for (int i = 0; i < 6; i++) { sum1 += arr[i]; } for (int i = 6; i < 12; i++) { sum2 += arr[i]; } if (sum1 > sum2) { cout << "The first half of the array has a greater sum: "; for (int i = 0; i < 6; i++) { cout << arr[i] << " "; } } else { cout << "The second half of the array has a greater sum: "; for (int i = 6; i < 12; i++) { cout << arr[i] << " "; } } return 0;
using namespace std;
int main() {
cout << "Enter 12 integers: ";int arr[12];
int sum1 = 0, sum2 = 0;
for (int i = 0; i < 12; i++) {
cin >> arr[i];
}
for (int i = 0; i < 6; i++) {
sum1 += arr[i];
}
for (int i = 6; i < 12; i++) {
sum2 += arr[i];
}
if (sum1 > sum2) {
cout << "The first half of the array has a greater sum: ";
for (int i = 0; i < 6; i++) {
cout << arr[i] << " ";
}
} else {
cout << "The second half of the array has a greater sum: ";
for (int i = 6; i < 12; i++) {
cout << arr[i] << " ";
}
}
return 0;
}