Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Return numbers of even digits in n
- public static int NumEvenDigits(int n)
- {
- // counter for even numbers
- int count = 0;
- // 0 is a even number so return 1;
- if (n == 0)
- {
- return 1;
- }
- while (n != 0)
- {
- // if last digit of n is even, add 1 to count
- if (Math.Abs(n % 10)%2 == 0)
- {
- count++;
- }
- // remove last digit from n
- n /= 10;
- }
- return count;
- }
Add Comment
Please, Sign In to add comment