Answer to Question #311234 in C# for chi

Question #311234

Machine Problem 5.10

Write a program using one-­‐dimensional array that searches a number if it is found on

the list of the given 5 input numbers and locate its exact location in the list.

Sample input/output dialogue:


Enter a list of numbers: 5 4 8 2 6

Enter a number to be searched: 2 2 found in location 4


1
Expert's answer
2022-03-14T08:39:52-0400
using System;

namespace one_dim_mas
{
    class Program
    {
        public static void Main(string[] args)
        {
            int i, n, search;
            n = 5;
            int [] array = new int[n];        
            Console.WriteLine("Enter a list of numbers:");
            for (i=0; i<n; i++)
                array[i] = Convert.ToInt32(Console.ReadLine());
            Console.Write("Enter a number to be searched: ");
            search = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine();
            for (i=0; i<n; i++)
                if (search == array[i])
                {
                Console.WriteLine("{0} found in location {1}", search, i+1);
                break;
                }
            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