Author : Rahul
Write a program to check whether entered number is even or odd
If a number is fully divisible by 2 then the number is said to be an even number otherwise the number is said to be an odd number.
Program:
using System;
namespace ProgrammingQuestion
{
class Program
{
static void Main(string[] args)
{
//Variable Declaration
string checkVal, message;
int checkNum;
bool isEven;
//User Input
Console.Write("Enter Number:");
checkVal = Console.ReadLine();
checkNum = Convert.ToInt32(checkVal);
//Odd/Even Logic
isEven = checkNum % 2 == 0;
//Print Result
if(isEven)
{
message = $"Entered Number {checkNum} is an even number.";
}
else
{
message = $"Entered Number {checkNum} is an odd number.";
}
Console.WriteLine(message);
Console.Read();
}
}
}
Output:
Enter Number:14
Entered Number 14 is an even number.