Click here to hide categories Click here to show left categories

User: Home          welcome : Guest          Log In / Register here     




C# interview questions with answers: - Find if number is even or odd ?

This is a damn simple c# interview questions on even and odd numbers. But recently one of our fresher friends failed to answer it. So we thought of writing a simple article on the same.

A number is even if remainder yields zero when divided by “2”. A number is odd when remainder yields zero, if divided by “3”. You get the remainder value by using the “%” sign.

Below is a simple code which shows how to check for even and odd number in c#.
 

Console.WriteLine("Enter your number");

int num = Convert.ToInt16(Console.ReadLine());

if (num % 2 == 0) // Is the remainder zero
{
      Console .WriteLine("Even number");
 }
else
{
       Console .WriteLine("Odd number");
}

Helpful Website Url
http://www.questpond.com
Share this article   |    Print    |    Article read by 4923 times
Author:
Shivprasad koirala Koirala
I am a Microsoft MVP for ASP/ASP.NET and currently a CEO of a small E-learning company in India. We are very much active in making training videos , writing books and corporate trainings. Do visit my site http://www.questpond.com for .NET, C# , design pattern , WCF , Silverlight , LINQ , ASP.NET , ADO.NET , Sharepoint , UML , SQL Server training and Interview questions and answers
Related Articles: No related article
Related Interview Questions: No related interview question