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!”.
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();
}
}
}
Comments
Leave a comment