diff --git a/Lesson_1/Task_3/Program.cs b/Lesson_1/Task_3/Program.cs new file mode 100644 index 0000000..6105750 --- /dev/null +++ b/Lesson_1/Task_3/Program.cs @@ -0,0 +1,42 @@ +/* +* 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 numbers = new List(); +string? userInput; + +for (int i = 0; i < 10; i++) +{ + int newNumber; + + do + { + Console.Write(string.Format("Enter number {0}: ", i + 1)); + userInput = Console.ReadLine(); + } while (!int.TryParse(userInput, out newNumber)); + + numbers.Add(newNumber); +} + +do +{ + Console.Write("Enter a number to duplicate: "); + userInput = Console.ReadLine(); +} while (!int.TryParse(userInput, out duplicate)); + +for (int i = 0; i < numbers.Count; i++) { + if (numbers[i] == duplicate) + { + numbers.Insert(i, duplicate); + i++; + } +} + +Console.WriteLine( + string.Join(", ", + numbers.Select(number => number.ToString()) + ) +); diff --git a/Lesson_1/Task_3/Task_3.csproj b/Lesson_1/Task_3/Task_3.csproj new file mode 100644 index 0000000..f02677b --- /dev/null +++ b/Lesson_1/Task_3/Task_3.csproj @@ -0,0 +1,10 @@ + + + + Exe + net7.0 + enable + enable + + +