Ejercicio
Números impares descendentes
Objetivo
Cree un programa en C# para mostrar en pantalla los números impares del 15 al 7 (hacia abajo), 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 number = 15; // Declaring and initializing the starting number as 15
// Using a while loop to display odd numbers from 15 to 7 in descending order
while (number >= 7) // The loop continues as long as the number is greater than or equal to 7
{
// Checking if the current number is odd
if (number % 2 != 0) // If the number is not divisible by 2, it is odd
{
// Printing the current odd number
Console.WriteLine(number); // Displaying the current odd number
}
number--; // Decrementing the number by 1 after each iteration
}
}
}