Advertisement
VelizarAvramov

11. Odd Number

Jul 17th, 2018
335
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.76 KB | None | 0 0
  1. Take as an input an odd number and print the absolute value of it. If the number is even, print "Please write an odd number." and continue reading numbers.
  2. using System;
  3.  
  4. namespace _11._Odd_Number
  5. {
  6.     class OddNumber
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             int n = Math.Abs(int.Parse(Console.ReadLine()));
  11.  
  12.             while (true)
  13.             {
  14.                 if (n % 2 == 0 )
  15.                 {
  16.                     Console.WriteLine("Please write an odd number.");
  17.                 }
  18.                 else
  19.                 {
  20.                     Console.WriteLine($"The number is: {n}");
  21.                     break;
  22.                 }
  23.                 n = Math.Abs(int.Parse(Console.ReadLine()));
  24.             }
  25.         }
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement