Exercise
Odd numbers descending
Objetive
Write a C# program to display the odd numbers from 15 to 7 (downwards) on the screen using "while".
Example Code
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
}
}
}