write a program that ask a user to enter a number n and display the first n even number
public static void Main()
{
Console.Write("Enter a number: ");
string input = Console.ReadLine();
if(!int.TryParse(input, out int value))
{
Console.WriteLine("Incorrect input. Press any key..");
return;
}
Console.Write($"Even numbers: {string.Join(" ", Enumerable.Range(0, value + 1).Where(n => n % 2 == 0).ToArray())}");
Console.ReadLine();
}
Comments
Leave a comment