Windows Phone Developers

Tuesday, November 25, 2008

How to Get Remainder of a division using C# (.NET)

C# (.NET) Code to find odd / even numbers

In Visual Basic, Mod Function (x MOD Y) is used to get the remainder of a division. Similarly x % y is used to get the remainder in C#

public static void remainder()

{

short rem = 51 % 5;

Console.WriteLine(rem);

try

{

short input = System.Convert.ToInt16(Console.ReadLine());

if (input % 2 == 0)

{

Console.WriteLine("Even number");

}

else

{

Console.WriteLine("Odd Number");

}

}

catch (FormatException ex1)

{

Console.WriteLine("Please enter numerals only");

}

}


Digg Technorati Delicious StumbleUpon Reddit BlinkList Furl Mixx Facebook Google Bookmark Yahoo
ma.gnolia squidoo newsvine live netscape tailrank mister-wong blogmarks slashdot spurl StumbleUpon

1 comment: