Answer to Question #309753 in C# for chi

Question #309753

Machine Problem 5.5.

Write a program using two dimensional arrays that searches a number and display the number of times it occurs on the list of 12 input values.


Sample input/output dialogue:

Enter twelve numbers: 20 13 30 35 40 16 18 20 18 20

Enter a number to search: 20 Occurrence(s) : 3


1
Expert's answer
2022-03-11T07:24:40-0500
using System;

namespace twodimension
{
    class Program
    {
        public static void Main(string[] args)
        {
            int i,j, search, cnt;
            int [ , ] array = new int[3,4];
            cnt = 0;
            Console.WriteLine("Enter twelve numbers:");
            for (i=0; i<3; i++)
                for (j=0; j<4; j++)
                    array[i,j] = Convert.ToInt32(Console.ReadLine());
            Console.Write("Enter a number to search: ");
            search = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine();
            Console.WriteLine("Array: ");
            for (i=0; i<3; i++)
            {
                for (j=0; j<4; j++)
                {
                    Console.Write("{0} ", array[i,j]);
                    if (search == array[i,j])
                        cnt++;
                }
                Console.WriteLine();
            }
            Console.WriteLine();
            Console.WriteLine("Occurrence(s): {0}", cnt);
            Console.Write("Press any key to continue . . . ");
            Console.ReadKey(true);
        }
    }
}

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