Nested Loops 2. Equal Sums Odd Even position
#include <iostream>
#include <cmath>
#include <string>
using namespace std;
int main()
{
int start, end;
cin >> start;
cin >> end;
for (int num = start; num <= end; num++) {
int number = num;
string numberStr = to_string(number);
int evenSum = 0;
int oddSum = 0;
for (int i = 0; i < 6; i++) {
int digit = numberStr[i] - 48;
if ((i + 1) % 2 == 0) {
evenSum += digit;
}
else {
oddSum += digit;
}
}
if (evenSum == oddSum) {
cout << number << " ";
}
return 0;
}
}