This is a C++ program that prints the odd elements in an integer array.
numbers
with 9 elements.begin
iterator from the end
iterator of the numbers
array, and assigns it to the arrayLength
variable.numbers
array from index 0 to arrayLength - 1
inclusive.numbers[i]
) is odd or not, by checking if its remainder when divided by 2 is not equal to 0 (numbers[i] % 2 != 0
).#include <iostream>
using namespace std;
int main() {
int numbers[] = {33, 431, 41, 76, 83, 99, 46, 9, 22};
int arrayLength = end(numbers) - begin(numbers);
for (int i = 0; i < arrayLength; i++) {
if (numbers[i] % 2 != 0) {
cout << numbers[i] << " ";
}
}
return 0;
}
33 431 41 83 99 9