Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Program
- {
- static void Main(string[] args)
- {
- Console.Write("Введите размер:");
- int n = Convert.ToInt32(Console.ReadLine());
- int[] arr=new int [n];
- for (int i=0;i<n;i++)
- {
- Console.Write("Arr[{0}]=", i);
- arr[i] = Convert.ToInt32(Console.ReadLine());
- }
- Console.WriteLine("Текущий массив: {0}", string.Join(", ", arr));
- int k;
- do
- {
- Console.Write("Введите элемент для вставки: ");
- }
- while (!int.TryParse(Console.ReadLine(), out k));
- int last = 0;
- for (int i = arr.Length - 1; i > 0; --i)
- if (arr[i] > 0)
- {
- last = i;
- break;
- }
- int[] narr = new int[arr.Length + 1];
- for (int i = 0, j = 0; j < narr.Length; ++i, ++j)
- {
- narr[j] = arr[i];
- if (j == last)
- {
- ++j;
- narr[j] = k;
- }
- }
- Console.WriteLine("Измененный массив: {0}", string.Join(", ", narr));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment