Monday, March 17, 2014

Mod Function_Ex_3 (Wk-4), Jan 27-31, 2014

Question: Request two integer N1 and N2.
Display whether N1 is divisible by N2 or N2 is divisible by N1 or neither.

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

namespace Mod_Function_Ex_3
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("\nEnter first value N1: ");
            int N1 = int.Parse(Console.ReadLine());
            Console.Write("\nEnter second value N2: ");
            int N2 = int.Parse(Console.ReadLine());

            if(N1 % N2 == 0)
            {
                Console.WriteLine("N1: {0} is divisible by N2 {1}", N1, N2);
            }
            else if (N2 % N1 == 0)
            {
                Console.WriteLine("N2: {0} is divisible by N1 {1}", N2, N1);
            }
            else
            {
                Console.WriteLine("Neither is divisible");
            }
            Console.ReadLine();
        }
    }
}

No comments:

Post a Comment