Sponsored Ad

Sunday, May 6, 2012

Find Out if a Given Number is Divisible by 3 in C#

To check if number is divisible by 3 or not you have to use the mode operator and if reminder is 0 it means it is divisible.

Find Out if a Given Number is Divisible by 3 in C#

using System;

namespace ConsoleHub
{
    class Programs
    {       
        static void Main(string[] args)
            {

                Console.WriteLine("Enter a Number:");
                int intDiv3 = Convert.ToInt16( Console.ReadLine());
                if (intDiv3 % 3 == 0)
                {
                    Console.WriteLine("The Number {0} is Divisible by 3", intDiv3);
                }
                else
                {
                    Console.WriteLine("The Number {0} is NOT Divisible by 3", intDiv3);
                }

                Console.ReadLine();
            }       
    }   
}

No comments:

Post a Comment

Sponsored Ad

Development Updates