C# is a modern, object-oriented, general-purpose programming language that is easy to learn and use. C# is syntactically similar to Java and is simple to learn for users who are already familiar with C, C++, or Java. The main features of the C# language are modern, simple, fast, open-source, cross-platform, secure, versatile, and most widely used in mobile and web applications, web services, websites, games, and databases. This section contains many examples of C# programming, from simple programs to complex and advanced C# programs.
These examples range from basic C# programs to mathematical functions, data types, operators, arrays, matrix, strings, preprocessor attributes, LINQ, functions, delegates, inheritance, file handling, event handling, exception handling, networking, interfaces, threads, and games. Every example program includes the problem description, problem solution, source code, program explanation, and run-time test cases. All C# examples have been compiled and tested on Visual Studio.
This is a C# Program to check whether the entered number is even or odd.
Problem Description
This C# Program checks if a given integer is Odd or Even.
Problem Solution
Here if a given number is divisible by 2 with the remainder 0 then the number is an Even number. If the number is not divisible by 2 then that number will be an Odd number.
Program/Source Code
Here is source code of the C# program which checks a given integer is odd or even. The C# program is successfully compiled and executed with Microsoft Visual Studio. The program output is also shown below.
/*
* C# Program to Check whether the Entered Number is Even or Odd
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace check1
{
class Program
{
static void Main(string[] args)
{
int i;
Console.Write(“Enter a Number : “);
i = int.Parse(Console.ReadLine());
if (i % 2 == 0)
{
Console.Write(“Entered Number is an Even Number”);
Console.Read();
}
else
{
Console.Write(“Entered Number is an Odd Number”);
Console.Read();
}
}
}
}