C# Program to print even numbers from 1 to N
In this C# program, we will take input from the user and print even numbers between 1 and the number input by the user. A even number is a positive integer that is exactly divisible by 2.
C# Program to print even numbers from 1 to N Code:
private static void Main(string[] args)
{
Console.WriteLine("Enter the nth No");
int nthNo = Int32.Parse(Console.ReadLine());
Console.Write("Even numbers between 1 and {0} are: ", nthNo);
for (n = 1; n <= nthNo; n++)
{
if (n%2==0)
Console.Write("{0} ", n);
}
Console.Write("\n");
Console.ReadLine();
}
C# Program to print even numbers from 1 to N Output:
