Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApplication26
- {
- class Program
- {
- static void Main(string[] args)
- {
- int x = 0;
- int y = 0;
- try
- {
- Console.WriteLine("Enter 1st no ");
- x = Convert.ToInt32(Console.ReadLine());
- Console.WriteLine("Enter 2nd no ");
- y = Convert.ToInt32(Console.ReadLine());
- Console.WriteLine("Sum: " + (x + y));
- Console.WriteLine("Difference: " + (x - y));
- Console.WriteLine("Product: " + (x * y));
- Console.WriteLine("Quotient: " + (x / y));
- Console.WriteLine("Remainder: " + (x % y));
- }
- catch (FormatException e)
- {
- Console.WriteLine("Not an integer");
- }
- catch (OverflowException e)
- {
- Console.WriteLine("Number too big or too small");
- }
- catch (DivideByZeroException e)
- {
- if (x == 0)
- Console.WriteLine("Quotient: undefined quantity");
- else if (x > 0)
- Console.WriteLine("Quotient: +infinity");
- else if (x < 0)
- Console.WriteLine("Quotient: -infinity");
- }
- catch (Exception e) //best practice
- {
- Console.WriteLine(e.Message);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement