Answer to Question #272860 in C# for haha

Question #272860

write a program that ask a user to enter a number n and display the first n even number


1
Expert's answer
2021-11-28T18:41:20-0500
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();
    }

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS