THANKS FOR WATCHING MY BLOG.IF ANY PROBLEM PLEASE COMMENT

Wednesday, 30 January 2013

Even or odd – A sample program in C#

Description:


Here in this program, The conditional statement (If statement)is used with the condition (i.e) The remainder value is zero or non zero when dividing the given value by 2, Conslole.WriteLine is used to display  the given value is even or odd and Console.ReadLine is used to get the input value.


Sample Code:

using System;
using System.Collections.Generic;
using System.Text;

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

Sample Input_1:
Enter the value:
88
Sample Output: The given value is even

Sample Input_2:
Enter the value:
23
Sample Output: The given value is odd

No comments:

Post a Comment