Advertisement
Guest User

Untitled

a guest
Oct 7th, 2014
427
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 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 _01.SquareRoot
  8. {
  9. class SquareRoot
  10. {
  11. static void Main()
  12. {
  13. try
  14. {
  15. Console.WriteLine("enter an integer number");
  16. int num = int.Parse(Console.ReadLine());
  17. if (num < 0)
  18. {
  19. throw new ArgumentOutOfRangeException();
  20. }
  21. int squareRoot = (int)Math.Sqrt(num);
  22. Console.WriteLine("the square root of {0} is {1}", num, squareRoot);
  23. }
  24. catch (FormatException)
  25. {
  26. Console.WriteLine("Invalid number");
  27. }
  28. catch (ArgumentOutOfRangeException)
  29. {
  30. Console.WriteLine("Number should not be negative");
  31. }
  32. finally
  33. {
  34. Console.WriteLine("Good bye");
  35. }
  36. }
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement