Answer to Question #294393 in C# for ITSyndicate

Question #294393
In C# please.

Program 1
Create a program that will accept inputs into 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-07T12:51:02-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)
        {
            int[] CountArray = new int[20];
            int odd = 0;
            int even = 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)
                    even++;
                if (CountArray[i] % 2 != 0)
                    odd++;
            }

            Console.WriteLine("Odd count: {0}", odd);
            Console.WriteLine("Even count: {0}", even);

            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