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.

techstudy.org

Kindle Paperwhite High Resolution Display Tablet | Rs. 9999

  1. using System;
  2.  
  3. class Program
  4. {
  5.  
  6. static void Main(string[] args)
  7. {
  8.  
  9. int num;
  10.  
  11. //Reading a number from user
  12. Console.Write("Enter any number to check even or odd: ");
  13. num = Convert.ToInt32(Console.ReadLine());
  14.  
  15. switch (num % 2)
  16. {
  17. //If n%2 == 0
  18. case 0: Console.WriteLine(num+" is even number");
  19. break;
  20.  
  21. //Else if n%2 == 1
  22. case 1: Console.WriteLine(num +" is odd number");
  23. break;
  24. }
  25.  
  26. Console.ReadLine();
  27.  
  28. }
  29.  
  30. }

Result

C# language techstudy

     





Related Topics


Responses




Popular Posts

Facebook

Founded in 2016, Tech Study passionately delivers stylish and dynamic innovative information to programmer and technology lovers. http://www.techstudy.org/.