C# : Program to check whether number is even or odd

In this simple C# tutorial we check whether number entered by the user is even or odd. Here we take "float" datatype, you can also take "int" or "double" datatype too depending on the number entered by the user and variable "num" for the number entered by the user. To check whether the no is even or odd we were taking "if-else" condition statement.

using System;
​class check
{
 public static void Main(String []args)
 {
        float num;
        Console.WriteLine("Enter number:");
        num=Convert.ToInt32(Console.ReadLine());
        if(num%2==0)
        {
          Console.WriteLine("\nnum is even ");  
        }
        else 
        {
          Console.WriteLine("\nnum is ");     
        }
         
 }
}
SHARE

Raunak Hajela

Hi. I’m CEO/Founder of Kodestat. I’m Student, Geek, Web Designer, Developer, Blog Enthusiast and Player. Inspired to make things looks better. I like playing with codes plus I am marvel fan :-P You can check my design portfolio here. For consulation fell free to drop an email at raunakhajela@gmail.com.

  • Image
  • Image
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment