Advertisement
Sephinroth

prac 7 ex 5

Nov 17th, 2019
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.47 KB | None | 0 0
  1.  
  2.  
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7.  
  8. namespace practice
  9. {
  10.     class Program
  11.     {
  12.         static void Input (out int[] array)
  13.         {
  14.             Console.Write("Введите длину массива: ");
  15.             int n = int.Parse(Console.ReadLine());
  16.             array = new int[n];
  17.             for (int i = 0; i < array.Length; i++)
  18.             {
  19.                 Console.Write("a[{0}]: ", i+1);
  20.                 array[i] = int.Parse(Console.ReadLine());
  21.             }
  22.         }
  23.         static void Change(ref int[] array, int a, int b)
  24.         {
  25.             for (int i = 0; i < array.Length; i++)
  26.                 if (array[i] <= b && array[i] >= a)
  27.                 {
  28.                     for (int j = i; j < array.Length - 1; j++)
  29.                         array[j] = array[j+1];
  30.                     Array.Resize(ref array, array.Length - 1);
  31.                 }
  32.         }
  33.  
  34.         static void Print(int[] array)
  35.         {
  36.             for (int i = 0; i < array.Length; i++)
  37.                 Console.Write("{0} ", array[i]);
  38.         }
  39.  
  40.  
  41.         static void Main(string[] args)
  42.         {
  43.             int[] array;
  44.             Console.WriteLine("Введите заданный промежуток: ");
  45.             int a = int.Parse(Console.ReadLine());
  46.             int b = int.Parse(Console.ReadLine());
  47.             Input(out array);
  48.             Change(ref array, a, b);
  49.             Print(array);
  50.             Console.ReadKey();
  51.            
  52.  
  53.  
  54.         }
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement