Answer to Question #170758 in C# for John eric

Question #170758

Create a program using a one-dimensional array that accepts 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
2021-03-11T06:31:25-0500
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace Array
{
    class Program
    {
        static void Main(string[] args)
        {        
            int n = 5; //Number of array elements
            bool isFind = false; //Boolean variable to search for an element in an array
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
            {
                Console.WriteLine("Please enter the {0}st item:", i + 1); //Entering items from the keyboard
                a[i] = int.Parse(Console.ReadLine());
            }
            Console.WriteLine("Enter the number to search:");
            int k = int.Parse(Console.ReadLine());
            for (int i = 0; i < a.Length; i++)
            {
                if (a[i] == k)
                {
                    isFind = true;                   
                }             
            }
            if (isFind)
                Console.WriteLine("Found number found!");
            else
                Console.WriteLine("Search number lost!");           
            Console.ReadKey();
        }   
    }
}

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