Introducing Radical.sh

Forget Code launches a powerful code generator for building API's

ODD or EVEN in C#

If the % operator with 2 over a number yields zero then it will be even number. Otherwise it is odd.
Please remember and consider 0. It is neither odd nor even.

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace ConsoleApplication2
  7. {
  8. class Program
  9. {
  10. static void Main(string[] args)
  11. {
  12.  
  13. string input;
  14.  
  15. int j = 0;
  16.  
  17. int iConvert;
  18.  
  19. Console.WriteLine(" Enter the number: ");
  20.  
  21. input = Console.ReadLine();
  22.  
  23.  
  24. iConvert = Convert.ToInt32(input);
  25.  
  26. if (iConvert == 0)
  27. {
  28. Console.WriteLine("The given number is neither odd nor even ");
  29. }
  30.  
  31. else
  32. {
  33.  
  34. j = (iConvert % 2);
  35.  
  36. if (j == 0)
  37. {
  38.  
  39. Console.WriteLine("The given number is even ");
  40.  
  41. }
  42.  
  43. else
  44. {
  45.  
  46. Console.WriteLine("The given number is odd ");
  47.  
  48. }
  49. }
  50. }
  51. }
  52. }
  53.  


Output :
  1. 42 --> Even number
  2. 21 --> Odd number
  3. 0 --> Neither odd nor even