Last active
August 20, 2017 21:12
-
-
Save mohnoor94/9c74f643752a433316d11aca516c711d to your computer and use it in GitHub Desktop.
A full C++ program includes a function that takes as a parameter an integer, and returns the number of odd and even digits.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // www.abukhleif.com | |
| #include <iostream> | |
| using namespace std; | |
| void EvenOdd (int num, int& evens, int& odds) { | |
| evens = odds = 0; | |
| while (num != 0) { | |
| if (num % 2 == 0) | |
| evens++; | |
| else | |
| odds++; | |
| num /= 10; | |
| } | |
| } | |
| int main() { | |
| int number, evenNums, oddNums; | |
| number = -123456789; | |
| EvenOdd(number, evenNums, oddNums); | |
| cout<<"There are (" << evenNums << ") even digits and (" | |
| << oddNums << ") odd digits in the number (" | |
| << number <<")."; | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment