Write a program to identify whether the number entered bya user is even or odd??
1
Expert's answer
2013-03-25T10:06:13-0400
using System; using System.Collections.Generic; using System.Linq; using System.Text;
namespace EvenOdd { class Program { static void Main(string[] args) { int number;//input number Console.Write("Enter number: ");//enter number number = int.Parse(Console.ReadLine());//read number if (IsOdd(number)) {//check if number is odd Console.WriteLine("Enter number is Odd. "); } if (IsEven(number))//check is number is even { Console.WriteLine("Enter number is Even."); } Console.WriteLine("Press any key to exit...."); Console.ReadLine(); } // function check odd number static bool IsOdd(int value) { return value % 2 != 0; } // function check even number static bool IsEven(int value) { return value % 2 == 0; } } }
Comments
Leave a comment