Answer to Question #309770 in C# for chi

Question #309770

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: E

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:37:15-0400

Here is program:

 static void Main(string[] args)
        {
            int[] arr = new int[5];
            int f = 0;
            int numsearch;
            Console.WriteLine("Enter a list of numbers:");
            for(int i = 0; i < arr.Length; i++)
            {
                arr[i] = Int32.Parse(Console.ReadLine());
            }
            Console.WriteLine("Enter a number to be searched:");
            numsearch = Int32.Parse(Console.ReadLine());
            foreach(int j in arr)
            {
                if(j == numsearch)
                {
                    Console.WriteLine(numsearch + " found in location " + f)
                        break;
                }
                f++;
            }


        }

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