Divide by Zero Exception

using System;
class Program
{
    public static void Main(String[] args)
    {
        int a = 10,res;
        for (int i = 5; i >= -5; i--)
        {
            try
            {
                res = a / i;
                Console.WriteLine(res);
            }
            catch (DivideByZeroException)
            {
                Console.WriteLine("Cant Divide by Zero");
            }
        }
        Console.ReadKey();
    }
}

No comments:

Post a Comment