Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- int evens_count(long long int num)
- {
- int count = 0;
- int prev_checked = -1;
- bool counting = false;
- while (num >= 0)
- {
- if (prev_checked % 2 == 0)
- {
- if (num != 0 && num % 2 == 0)
- {
- counting = true;
- count++;
- }
- else if (counting)
- {
- counting = false;
- count++;
- }
- }
- if (num == 0)
- break;
- prev_checked = num % 10;
- num /= 10;
- }
- return count;
- }
- int main() {
- std::cout << evens_count(22);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement