We are providing online training of realtime Live project on Asp.Net MVC with Angular and Web API. For more information click here. If you have any query then drop the messase in CONTACT FORM

Sunday, June 14, 2015

Write a program input the array element and sum the Even numbers and Odd numbers.


      class Program
    {
        static void Main(string[] args)
        {

            int[] arr;

            int Even = 0, Odd = 0;
            Console.WriteLine("Enter the lenth of the array");
            int n = int.Parse(Console.ReadLine());
            Console.WriteLine("Enter the array Element");

            arr = new int[n];
            for (int i = 0; i < n; i++)
            {

                arr[i] = int.Parse(Console.ReadLine());

            }

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

                if (arr[i] % 2 == 0)
                {
                    Even += arr[i];
                }

                else
                {

                    Odd += arr[i];
                }
            }

            Console.WriteLine("Sume of Even Number {0}", Even);
            Console.WriteLine("Sum of Odd Number {0}", Odd);
            Console.ReadLine();

        }


    }
Output:

    

No comments: