How do I Write a program to take N numbers as input and output all even numbers from 1 to N inclusive in C# | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

How do I Write a program to take N numbers as input and output all even numbers from 1 to N inclusive in C#

I’m having difficulty with this question. I have the first part down as Int num = Convert.ToInt32(Console.ReadLine()); While (num <= 10) { Console.WriteLine(num); num ++; } I’m suppose to make the console output it in even numbers starting from 1 but I’m confused with the examples and in my opinion they don’t show you how to do it, so I’ve been stumped for a few days. Any help is appreciated. Thank you in advance.

26th Jan 2021, 11:13 PM
Brent Tyson
Brent Tyson - avatar
5 Answers
+ 7
You should create a new variable called curr and set it initially to 1. Every step, you print the value and then increment. Repeat until you printed the number you got as input.
26th Jan 2021, 11:26 PM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 5
//You could try this: int num = Convert.ToInt32(Console.ReadLine()); for (int i = 1; i <= num; i++) { if (i % 2 == 0) { Console.WriteLine(i); } } //For every number from one to num, if the number is divisible to 2, (if it is even), output the current number. //Hope this helps!!
26th Jan 2021, 11:34 PM
Paula Campbell
Paula Campbell - avatar
27th Jan 2021, 8:51 AM
Pee Frosh
Pee Frosh - avatar
+ 1
can you show me an example how that would be written out?
26th Jan 2021, 11:28 PM
Brent Tyson
Brent Tyson - avatar
+ 1
thank you for all the advice eveyone. much appreciated!
27th Jan 2021, 8:38 PM
Brent Tyson
Brent Tyson - avatar