Advertisement
svetoslavhl

Задача 1

Dec 22nd, 2013
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. using System;
  2.  
  3. class Program
  4. {
  5. static void Main(string[] args)
  6. {
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13. try
  14. {
  15.  
  16.  
  17.  
  18.  
  19. Console.WriteLine("Enter a number:");
  20. int num = int.Parse(Console.ReadLine());
  21.  
  22. if(num < 0)
  23. {
  24.  
  25. throw new ArithmeticException();
  26.  
  27. }
  28.  
  29.  
  30. Math.Sqrt(num);
  31. Console.WriteLine(Math.Sqrt(num));
  32.  
  33. }
  34. catch(FormatException )
  35. {
  36.  
  37. Console.WriteLine("Invalid number");
  38.  
  39. }
  40. catch (OverflowException)
  41. {
  42.  
  43. Console.WriteLine("Invalid number");
  44. }
  45. catch(ArithmeticException){
  46.  
  47. Console.WriteLine("Negative number");
  48.  
  49. }
  50. finally
  51. {
  52.  
  53. Console.WriteLine("Goodbye!");
  54.  
  55. }
  56. }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement