TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Silviu Felecan
NA
22
1k
Check each digit from a number if is odd or even
Aug 5 2020 9:11 AM
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:
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 the console I get eveneveneveneven (for 4444). Is there a way to get like a block or list with concatenate 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.
Reply
Answers (
1
)
Migrating an existing DotnetCore WebAPI into Azure Serverless function
How to reset pictures and the size of the image in word file using C#