Check Odd and even numbers - CSharp Language Basics

CSharp examples for Language Basics:if

Description

Check Odd and even numbers

Demo Code

using System;/*  ww w . j  a  v  a2 s .  co m*/
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program
{
   static void Main(string[] args)
   {
      // Input
      Console.Write("Enter a number: ");
      string input = Console.ReadLine();
      int number = Convert.ToInt32(input);
      // Remainder calculation
      int remainderAfterDivisionByTwo = number % 2;
      // Evaluation
      if (remainderAfterDivisionByTwo == 0)
      {
         Console.WriteLine("The number is even");
      }
      else
      {
         Console.WriteLine("The number is odd");
      }
   }
}

Result


Related Tutorials