In this example, i’ll show you How to check even or odd number using switch case in C# Console App.
C# Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | 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(); } |
Output: