Answer to Question #309751 in C# for chi

Question #309751

Machine Problem 5.3.

Write a program using one-­‐dimensional array that accept five input values from the keyboard. Then it should also accept a number to search. This number is to be searched if it is among the five input values. If it is found, display the message “Searched number is found!”, otherwise display “Search number is lost!”.


1
Expert's answer
2022-03-11T07:24:34-0500

Here is my program:

  static void Main(string[] args)
        {
            int[] arr = new int[5];
            int numtosearch;
            Console.WriteLine("Enter values array: ");
            for(int i = 0; i < arr.Length; i++)
            {
                arr[i] = Int32.Parse(Console.ReadLine());
            }
            Console.WriteLine("Enter number to search:");
            numtosearch = Int32.Parse(Console.ReadLine());
            foreach(int i in arr)
            {
                if (numtosearch == i)
                {
                    Console.WriteLine("Searched number is found!");
                    break;
                }
                else
                {
                    Console.WriteLine("Search number is lost!");
                }
            }
        }

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