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