Even or Odd

using System;

using System.Collections.Generic;

using System.Text;

 

namespace EvenOdd

{

    class EvenOdd

    {

        static void Main(string[] args)

        {

            try

            {

                string str = "123477756780 432134567789555";

                int digit1 = 0, digit2 = 0, flag = 0;

                for (int i = 0; i < str.Length; i++)

                {

                    char ch = char.Parse(str.Substring(i, 1));

                    if (ch != ‘ ‘ && flag == 0)

                    {

                        digit1 = int.Parse(ch.ToString());

                    }

 

                    else if (ch == ‘ ‘)

                    {

                        flag = 1;

                    }

 

                    else

                    {

                        digit2 = int.Parse(ch.ToString());

                    }

                }

                if (digit1 % 2 == 0 || digit2 % 2 == 0)

                {

                    Console.WriteLine("Product will be even");

                }

                else

                {

                    Console.WriteLine("Product will be odd");

                }

            }

            catch (Exception e)

            {

                Console.WriteLine(e.Message);

            }

 

        }

    }

}

Advertisements
This entry was posted in Information Technology. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s