C# program to take a number as input and tells its even or odd number
Following program shows you how to take a number as input and tells its even or odd number.
This program divides input by 2, If remainder is zero it prints even otherwise it prints odd
using System;
class MainClass {
public static void Main (string[] args) {
Console.WriteLine ("Please enter a number:");
int input = Convert.ToInt32(Console.ReadLine());
if (input % 2 == 0) {
Console.WriteLine("Even");
} else {
Console.WriteLine("Odd");
}
}
}
Output:
Example1:
Please enter a number:
6
Even
Example2:
Please enter a number:
9
Odd