Even numbers are those that are divisible by 2 without leaving a remainder, while odd numbers are not divisible by 2 without a remainder. In this article, we will explore how to write a simple C# program to check if a given number is even or odd.
Problem Statement: Write a C# program that takes an integer as input and determines whether it is an even or odd number.
Example:
Input: num = 7 Output: 7 is an Odd Number. Explanation: 7 % 2 = 1 Input: num = 10 Output: 10 is an Even Number. Explanation: 10 % 2 = 0
Steps to Check Even and Odd Numbers.
C# code to check Even and Odd Numbers.
// C-sharp code check if a number is even or odd using System; namespace EvenOddChecker { class Program { static void Main(string[] args) { Console.Write("Enter an integer: "); int number = Convert.ToInt32(Console.ReadLine()); if (number % 2 == 0) { Console.WriteLine($"{number} is an Even number."); } else { Console.WriteLine($"{number} is an Odd number."); } } } }
Enter an integer: 12
12 is an Even number.

