Write a program using one-dimensional array that searches a number if it is found on the list of the given 5 input numbers and locate its exact location in the list.
Sample input/output dialogue:
Enter a list of numbers: 5 4 8 2 6
Enter a number to be searched: 2 2 found in location 4
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Q176047
{
class Program
{
static void Main(string[] args)
{
Console.Write("Enter a list of numbers: ");
string[] numbers = Console.ReadLine().Split(' ');
Console.Write("Enter a number to be searched: ");
string numberSearched = Console.ReadLine();
for (int i = 0; i < numbers.Count(); i++)
{
if (numberSearched == numbers[i])
{
Console.WriteLine("{0} found in location {1}", numberSearched, i+1);
}
}
Console.ReadLine();
}
}
}
Comments
Leave a comment