Advertisement
VyaraG

DescendingOddNumbers

Nov 29th, 2014
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.65 KB | None | 0 0
  1. using System;
  2. //Create a program to display on the screen the odd numbers from n to m (downwards),
  3.  
  4. class DescendingOddNumbers
  5. {
  6.     static void Main()
  7.     {
  8.         Console.Write("Start from: ");
  9.         int n = int.Parse(Console.ReadLine());
  10.         Console.Write("To: ");
  11.         int m = int.Parse(Console.ReadLine());
  12.  
  13.         while ((n>=m))
  14.         {
  15.             if ((n % 2) != 0)
  16.             {
  17.                 Console.WriteLine("{0}", n);
  18.                 n -= 2;
  19.                
  20.             }
  21.             else
  22.             {
  23.                 Console.WriteLine(n-1);
  24.                 n --;
  25.             }
  26.            
  27.         }
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement