C++ Code Example: even numbers in an array

The code defines an integer array numbers with 9 elements and calculates the length of the array using end(numbers) - begin(numbers). The code then loops over the array and prints all the even numbers in the array. The check numbers[i] % 2 == 0 is used to determine if a given element of the array is even or odd. If the result of the modulo operation is 0, it means that the number is even and it will be printed. The code outputs the even numbers in the array separated by a space.

#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;
}
Output
76 46 22