Latest

random

C# Check Odd or Even

Logic for Even and Odd Numbers in C#

If a number is divisible by 2 with the remainder 0 then the number is called an Even number. If the number is not divisible by 2 then that number will be an Odd number. It is very easy to find the given number is odd or even in csharp. 
Find the below c# .net program example for practice, which checks a given integer is odd or even. 

Example 1 :-
.net c# programs,basic c# programs,c# code examples,odd even program example code
program to print even and odd numbers
namespace EvenOddNumber
{
    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("It's an even number");
                Console.Read();
            }

            else
            {
                Console.Write("It's an Odd Number");
                Console.Read();
            }
        }
    }

}

Here is the output of the C# Program:
Enter a Number : 8
It's an Even Number
Find Odd Even Numbers List from 1 to N

Example 2:     
int n;
            Console.Write("Input a max limit to display odd or even numbers : ");
            n = int.Parse(Console.ReadLine());
            for (int i = 1; i <= n; i++)
            {
                if (i % 2 == 0)
                {
                    Console.WriteLine("Number {0} is Even", i);
                }
                else
                {
                    Console.WriteLine("Number {0} is odd", i);
                }
            }

     Console.ReadKey();

No comments:

All Rights Reserved by Etechpulse © 2015 - 2016
Powered By Blogger

Contact Form

Name

Email *

Message *

Powered by Blogger.