Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Prodentim Probiotics Specially Designed For The Health Of Your Teeth And Gums

Instant Grammar Checker - Correct all grammar errors and enhance your writing

Teach Your Child To Read

Powerful WordPress hosting for WordPress professionals

Disclosure: My content contains affiliate links.

31,151 questions

40,705 answers

573 users

How to check odd or even using conditional (ternary) operator in C#

Freaking Awesome WordPress Hosting
1,414 views
asked May 12, 2015 by avibootz
edited May 12, 2015 by avibootz

1 Answer

0 votes
using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                Console.Write("Enter a number: ");
                int n = Convert.ToInt32(Console.ReadLine());
                Console.WriteLine((n % 2 == 0) ? "Even" : "Odd");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
     }
}

/*
run1:
   
Enter a number: 10
Even

run2:

Enter a number: 13
Odd
  
*/




answered May 12, 2015 by avibootz

Related questions

...