Skip to content

Instantly share code, notes, and snippets.

@mohnoor94
Last active August 20, 2017 21:12
Show Gist options
  • Select an option

  • Save mohnoor94/6998c86071e85f9b342fed3e148f27bb to your computer and use it in GitHub Desktop.

Select an option

Save mohnoor94/6998c86071e85f9b342fed3e148f27bb to your computer and use it in GitHub Desktop.
A C++ function that takes as a parameter an integer, and returns the number of odd and even digits.
// www.abukhleif.com
void EvenOdd (int num, int& evens, int& odds) {
evens = odds = 0;
while (num != 0) {
if (num % 2 == 0)
evens++;
else
odds++;
num /= 10;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment