Ejercicio
Repetir hasta 0
Objetivo
Cree un programa en C# para pedir al usuario un número "x" y mostrar 10*x. Debe repetirse hasta que el usuario ingrese 0 (usando "while").
Código de Ejemplo
using System; // Importing the System namespace to use Console functionalities
class Program
{
// Main method where the program execution begins
static void Main()
{
int x; // Declaring a variable to store the number entered by the user
// Asking the user to enter a number
Console.Write("Enter a number (enter 0 to stop): ");
x = Convert.ToInt32(Console.ReadLine()); // Converting the input to an integer
// Using a while loop to repeat the process until the user enters 0
while (x != 0) // While the user enters a number different from 0
{
// Displaying the result of 10 times the entered number
Console.WriteLine("10 * {0} = {1}", x, 10 * x); // Printing the result of 10 * x
// Asking the user to enter another number
Console.Write("Enter a number (enter 0 to stop): ");
x = Convert.ToInt32(Console.ReadLine()); // Converting the input to an integer again
}
// Displaying a message when the loop ends (when 0 is entered)
Console.WriteLine("You entered 0. The program has stopped."); // Printing a stop message
}
}