Answer to Question #294743 in C# for playhard

Question #294743

Create a program that will accept inputs into a 20-element one-dimensional integer

array CountArray. Your program should count the odd and even numbers that appeared in

the list of accepted values.


1
Expert's answer
2022-02-07T05:10:40-0500
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            /*
             * Create a program that will accept inputs into a 20-element one-dimensional integer
 array CountArray. Your program should count the odd and even numbers that appeared in
 the list of accepted values.
             */
            int[] CountArray = new int[20];
            int oddCount = 0;
            int evenCount = 0;

            for (int i = 0; i < CountArray.Length; i++)
            {
                Console.WriteLine("Input [{0}] number :", i + 1);
                CountArray[i] = Convert.ToInt32(Console.ReadLine());

            }

            for (int i = 0; i < CountArray.Length; i++)
            {
                if (CountArray[i] % 2 == 0)
                    evenCount++;
                if (CountArray[i] % 2 != 0)
                    oddCount++;
            }

            Console.WriteLine("Odd count: {0}", oddCount);
            Console.WriteLine("Even count: {0}", evenCount);

            Console.ReadKey();
        }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS