grigorb57

isOdd

Jun 7th, 2018
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.98 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApp4
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int inputOdd = int.Parse(Console.ReadLine());
  14.  
  15.             bool isOdd = inputOdd % 2 != 0;
  16.  
  17.             while (true)
  18.             {
  19.                 if (inputOdd % 2 != 0)
  20.                 {
  21.                     if (inputOdd < 0)
  22.                     {
  23.                         Console.WriteLine($"The number is: {Math.Abs(inputOdd)}");
  24.                         break;
  25.                     }
  26.                     Console.WriteLine($"The number is: {inputOdd}");
  27.                     break;
  28.                 }
  29.                 else if (isOdd == false)
  30.                 {
  31.                     Console.WriteLine("Please write an odd number.");
  32.                     inputOdd = int.Parse(Console.ReadLine());
  33.                 }
  34.             }
  35.         }
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment