int main() { int n; cout << "Enter the size of the array: "; cin >> n;
int arr[n]; cout << "Enter the elements of the array: "; for (int i = 0; i < n; i++) { cin >> arr[i]; } int minEven = INT_MAX; bool hasEven = false; for (int i = 0; i < n; i++) { if (arr[i] % 2 == 0 && arr[i] < minEven) { minEven = arr[i]; hasEven = true; } } if (hasEven) { cout << "The smallest even element in the array is: " << minEven << endl; } else { cout << "There are no even elements in the array. The first element is: " << arr[0] << endl; } return 0;
using namespace std;
int main() {
int arr[n];int n;
cout << "Enter the size of the array: ";
cin >> n;
cout << "Enter the elements of the array: ";
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
int minEven = INT_MAX;
bool hasEven = false;
for (int i = 0; i < n; i++) {
if (arr[i] % 2 == 0 && arr[i] < minEven) {
minEven = arr[i];
hasEven = true;
}
}
if (hasEven) {
cout << "The smallest even element in the array is: " << minEven << endl;
} else {
cout << "There are no even elements in the array. The first element is: " << arr[0] << endl;
}
return 0;
}