- Course
- Flow controls C
- Odd numbers in descending
Odd numbers in descending
Last updated:
8/23/2020
⁃
Difficulty:
Easy
Create a program in C# to show odd numbers from x to y in orden descending.
Input
49
3
Output
49 47 45 43 41 39 37 35 33 31 29 27 25 23 21 19 17 15 13 11 9 7 5 3
Solution
using System;
public class OddNumbersDescending
{
public static void Main()
{
int x = Convert.ToInt32(Console.ReadLine());
int y = Convert.ToInt32(Console.ReadLine());
if (x % 2 == 0) x--;
while (x >= y)
{
Console.Write(x + " ");
x -= 2;
}
}
}