Answer to Question #314615 in C# for mark

Question #314615

Write a program using one-dimensional array that accep t fiveinput 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-20T06:20:36-0400
using System;

namespace array
{
    class Program
    {
        public static void Main(string[] args)
        {
            int i, number;
            bool search;
            int [] array = new int[5];
            Console.WriteLine("Enter array:");
            for (i=0; i<5; i++)
                array[i] = Convert.ToInt32(Console.ReadLine());
            Console.Write("Enter nubmer to search: ");
            number = Convert.ToInt32(Console.ReadLine());
            search = false;
            for (i=0; i<5; i++)
                if (number == array[i])
                    search = true;
            Console.WriteLine();
            if (search)
                Console.WriteLine("Searched number is found!");
            else
                Console.WriteLine("Search number is lost!");
            Console.WriteLine();
            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