I need to test for odd and even each digit from a number

keeponfalling

New member
Joined
Aug 5, 2020
Messages
1
Programming Experience
Beginner
Hello all,

If you can please help me, I'm new to see sharp programming.

I need to display odd/even for each digit from a number like this:

4444
even
even
even
even

So, I extract each digit from the right - to the left (it was easy for me like this) and I have this code:

C#:
static void Main(string[] args)
        {
            string inputData = Console.ReadLine(); // the digit
            int number = Convert.ToInt32(inputData);
            int aDigit = number % 10000 / 1000;
            int bDigit = (number % 1000) / 100;
            int cDigit = (number % 10);
            int dDigit = (number % 100) / 10;
        }

To get odd/even from each digit I use the concatenate method, and combine each digit with the string name odd/even and in console I get: eveneveneveneven (for 4444). Is there a way to get the result like a block or a list with concatenate method with Console.WriteLine method?

Or is there with if/else function and display the odd/even result with - if (aDigit %2 ==0) - and return in console writeline even/odd like a list.

Thank you for your time.
 
Last edited by a moderator:
There is a much easier. Treat the input as a string to get each digit as a character. For each digit character, convert to integer. Check if the integer is odd or even.
 

Latest posts

Back
Top Bottom