Write a C# program to check whether a given substring is present in the given string

Write C# program to check even or odd number using switch case

Introduction

I have used Visual Studio 2012 for debugging purpose. But you can use any version of visul studio as per your availability.

using System;
 
class Program
{
 
    static void Main(string[] args)
    {
 
        int num;
 
        //Reading a number from user
        Console.Write("Enter any number to check even or odd: ");
        num = Convert.ToInt32(Console.ReadLine());
 
        switch (num % 2)
        {
            //If n%2 == 0
            case 0: Console.WriteLine(num+" is even number");
                break;
 
            //Else if n%2 == 1
            case 1: Console.WriteLine(num +" is odd number");
                break;
        }
 
        Console.ReadLine();
 
    }
 
}

Result

Write C# program to check even or odd number using switch case
Write C# program to check even or odd number using switch case

Add a Comment

Your email address will not be published. Required fields are marked *