This repository has been archived on 2024-10-24. You can view files and clone it, but cannot push or open issues or pull requests.
NG_2023_Stanislav_Mykhailenko/Lesson_1/Task_3/Program.cs

36 lines
668 B
C#
Raw Normal View History

2023-03-06 12:18:50 +00:00
/*
* Lesson 1 Task 3: get a list of ten numbers and duplicate a number entered by user
* Author: Stanislav Mykhailenko
* License: Unlicense
*/
int duplicate;
List<int> numbers = new List<int>();
for (int i = 0; i < 10; i++)
{
int newNumber;
do
{
2023-03-18 22:08:23 +00:00
Console.Write($"Enter number {i + 1}: ");
} while (!int.TryParse(Console.ReadLine(), out newNumber));
2023-03-06 12:18:50 +00:00
numbers.Add(newNumber);
}
do
{
Console.Write("Enter a number to duplicate: ");
2023-03-18 22:08:23 +00:00
} while (!int.TryParse(Console.ReadLine(), out duplicate));
2023-03-06 12:18:50 +00:00
for (int i = 0; i < numbers.Count; i++) {
if (numbers[i] == duplicate)
{
numbers.Insert(i, duplicate);
i++;
}
}
2023-03-18 22:08:23 +00:00
Console.WriteLine(String.Join(", ", numbers));