0
Display even numbers smaller than the value that the user chooses (from big to small) in c sharp
System.Console.Write("Please enter a number: "); String numberString = Console.ReadLine(); int index = System.Convert.ToInt32(numberString); int number = index; if (index % 2 == 0) { number = index; } else { number = index - 1; } for (int i = 0; i <= index; i++) { if (number % 2 == 0 && number > 0) { System.Console.WriteLine(number); number -= 2; } } //*********************************** how to write in another way with for loop and with while ?
1 Réponse
+ 4
// ie in this way:
String numberString = Console.ReadLine();
while(numberString != "e") {
// you code
numberString = Console.ReadLine();
// all the code will repeated
// until user enter e
}