Read an integer (use 42) and print whether it is even or odd.
Ready — edit the code above and click Run.
using System;
class Program
{
static void Main()
{
int n = 42;
Console.WriteLine(n % 2 == 0 ? "Even" : "Odd");
}
}
Try solving on your own first, then reveal the official answer.
Modulo % 2 is zero for even numbers—common interview warm-up.