kirililchev3

Odd number - while loop + math abs

May 17th, 2018
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.52 KB | None | 0 0
  1. using System;
  2.  
  3.     class Program
  4.     {
  5.     private static void Main()
  6.     {
  7.      
  8.             int num = int.Parse(Console.ReadLine());
  9.  
  10.  
  11.         while (num % 2 == 0)
  12.         {
  13.             num = int.Parse(Console.ReadLine());
  14.             Console.WriteLine("Please write an odd number.");
  15.         }
  16.        
  17.             Console.WriteLine($"The number is: {Math.Abs(num)}"); // Math.Abs превръща ми отрицателно число в положително
  18.        
  19.        
  20.  
  21.         }
  22.     }
Advertisement
Add Comment
Please, Sign In to add comment