Answer to Question #190609 in C# for angelo r reyes

Question #190609

Write a program using two-dimensional arrays that lists the Odd numbers and Even numbers separately in a given 12 input values.


Sample input/out dialogue:


Enter twelve numbers: 15 20 13 35 40 16 18 20 18 20 19

Odd numbers are: 15 13 35 19

Even numbers are: 40 16 18 20 18 20


1
Expert's answer
2021-05-07T23:06:53-0400
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;


namespace C_SHARP
{
   


    class Program
    {
        static void Main(string[] args)
        {
            int[,] oddEvenNumbers = new int[2, 12];
            int counterOddNumbers = 0;
            int counterEvenNumbers = 0;
            Console.Write("Enter twelve numbers: ");
            string[] numbersStr = Console.ReadLine().Split(' ');
            for (int i = 0; i < numbersStr.Length; i++)
            {
                int number = int.Parse(numbersStr[i]);
                if (number % 2 != 0)
                {
                    //Odd numbers 
                    oddEvenNumbers[0, counterOddNumbers] = number;
                    counterOddNumbers++;
                }
                else
                {
                    //Even numbers 
                    oddEvenNumbers[1, counterEvenNumbers] = number;
                    counterEvenNumbers++;
                }
            }
            Console.Write("Odd numbers are: ");
            for (int i = 0; i < counterOddNumbers; i++)
            {
                Console.Write(oddEvenNumbers[0, i] + " ");
            }
            Console.Write("\nEven numbers are: ");
            for (int i = 0; i < counterEvenNumbers; i++)
            {
                {
                    Console.Write(oddEvenNumbers[1, i] + " ");
                }
             
            }
            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