The exercise template contains a base that reads numbers from the user and adds them to a list. Reading is stopped once the user enters the number -1.
Expand the program to ask for a start and end indices once it has finished asking for numbers. After this the program shall prints all the numbers in the list that fall in the specified range (between the indices given by the user, inclusive). You may assume that the user gives indices that match some numbers in the list.
> 72
> 2
> 8
> 11
> -1
From where?
> 1
Where to?
> 9
2
8
public static void Main(string[] args)
{
List<int> list = new List<int>();
while (true)
{
int input = Convert.ToInt32(Console.ReadLine());
if (input == -1)
{
break;
}
list.Add(input);
}
Console.WriteLine("From where");
int number = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("To where");
int number2 = Convert.ToInt32(Console.ReadLine());
for (int i = 0; i < list.Count; i++)
Console.WriteLine(i);
Last edited: