Thursday 22 August 2013

Even or odd – A sample program in C#

Q:-1    Even or odd – A sample program in C#



Ans:-   using System;
using System.Collections.Generic;
using System.Text;

namespace codeforevenorodd
{
    class Program
    {
        static void Main(string[] args)
        {
            int g;
            int j = 0;
            int i;
            Console.WriteLine("Enter any Value");
            g = Convert.ToInt32(Console.ReadLine());
            i=Convert.ToInt32(g);
            j = (i % 2);
            if (j  == 0)
            {
                Console.WriteLine("The given value is Even");
                Console.ReadLine();
            }
            else
            {
               
                Console.WriteLine("The given value is odd");
                Console.ReadLine();
            }
        }
    }
}

No comments:

Post a Comment