Monday, 29 April 2013

Write a program to accept two numbers and check if the first is divisible by the second. In addition, an error message should be displayed if the second number is zero. (Duration: 40 min)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int num1, num2, result;
            Console.WriteLine("Enter First Number");
            num1 = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("Enter socond Number");
            num2 = Convert.ToInt32(Console.ReadLine());
            if (num2 == 0)
            {
                Console.WriteLine("You cannot divide by 0");
            }
            else
            {
                result = num1 % num2;
                if (result ==0)
                    Console.WriteLine("Divisidle");
                else

                Console.WriteLine("Not DIvisible");
            }

        }
    }

}

No comments:

Post a Comment