fofo

mail@pastecode.io avatar
unknown
c_cpp
2 years ago
886 B
6
Indexable
Never
#include <iostream>

void computeNumber(int maxDigits, int digits[], int currentNumDigits) {

    if (currentNumDigits >= maxDigits) {
        int sum = 0;
        for (int i = 0; i < currentNumDigits; ++i)
            sum += digits[i];

        if (sum % 2 == 0) {
            for (int i = 0; i < currentNumDigits; ++i)
                std::cout << digits[i];
            std::cout << '\n';
        }

        return;
    }

    for (int i = 0; i < 10; ++i) {
        if (!currentNumDigits && !i)
            continue;

        digits[currentNumDigits] = i;

        computeNumber(maxDigits, digits, currentNumDigits + 1);
    }
}

int main() {
    int n;
    int digits[8] = { 0 };

    std::cout << "Please input a number.\n";
    std::cin >> n;

    std::cout << "The computed numbers are:\n";
    computeNumber(n, digits, 0);

    return 0;
}