Advertisement
Qrist

Array's size decrease by 1

Apr 22nd, 2020
303
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.92 KB | None | 0 0
  1. using System;
  2. using static System.Console;
  3.  
  4. class Program
  5. {
  6.     public static void Main(string[] args)
  7.     {
  8.         Random rd = new Random();
  9.         int[] a = new int[10];
  10.  
  11.         for (int i = 0; i < a.Length; i++)
  12.         {
  13.             a[i] = rd.Next(-50, 50);
  14.             Write(a[i] + " ");
  15.         }
  16.         do
  17.         {
  18.             WriteLine("Enter index");
  19.             int pos = int.Parse(ReadLine());
  20.             int[] temp = new int[a.Length - 1];
  21.             if (pos < 0 || pos > a.Length) { continue; }
  22.             for (int i = 0; i < pos; i++)
  23.             {
  24.                 temp[i] = a[i];
  25.             }
  26.             for (int i = pos; i < temp.Length; i++)
  27.             {
  28.                 temp[i] = a[i + 1];
  29.             }
  30.             a = temp;
  31.             foreach (int x in a)
  32.             {
  33.                 Write(x + " ");
  34.             }
  35.             WriteLine();
  36.         } while (true);
  37.     }
  38.    
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement