Advertisement
BSO90

CopyFrom

Jul 5th, 2021
734
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.02 KB | None | 0 0
  1. int[] sourceArray = Console.ReadLine().Split().Select(int.Parse).ToArray();
  2.             int[] destinationArray = Console.ReadLine().Split().Select(int.Parse).ToArray();
  3.             int sourceStartIndex = int.Parse(Console.ReadLine());
  4.             int destStartIndex = int.Parse(Console.ReadLine());
  5.             int count = int.Parse(Console.ReadLine());
  6.  
  7.  
  8.             if (sourceStartIndex >= 0 && sourceStartIndex < sourceArray.Length && destStartIndex + count >= 0 && destStartIndex + count < destinationArray.Length)
  9.             {
  10.                 int endIndex = sourceStartIndex + count;
  11.                 for (int i = sourceStartIndex; i <= endIndex; i++)
  12.                 {
  13.                     destinationArray[destStartIndex] = sourceArray[i];
  14.                     destStartIndex++;
  15.                 }
  16.             }
  17.             else
  18.             {
  19.                 Console.WriteLine("Throw index out of range exception");
  20.                 return;
  21.             }
  22.  
  23.             Console.WriteLine(String.Join(" ", destinationArray));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement