kisame1313

1.3.9.4

Jul 19th, 2017
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.38 KB | None | 0 0
  1. using System;
  2.  
  3. namespace ConsoleApplication
  4. {
  5.     class Program
  6.     {
  7.         /*
  8.          * Сделайте 3 метода:
  9.          *  - Удаление элемента из массива.
  10.          *  - Добавление элемента в массив.
  11.          *  - Перенос одного массива в другой.
  12.          */
  13.  
  14.         static void Main ( string [] args )
  15.         {
  16.             int [] nums = new int [4] { 1,2,3,4 };
  17.             int [] nums2 = Transfer ( nums );
  18.             foreach ( int i in nums2 )
  19.             {
  20.                 Console.WriteLine ( i );
  21.             }
  22.         }
  23.  
  24.         static int [] Delete ( int [] arr )
  25.         {
  26.             int [] newArray;
  27.  
  28.             if ( arr.Length > 1 )
  29.             {
  30.                 newArray = new int [arr.Length - 1];
  31.  
  32.                 for ( int i = 0 ; i < newArray.Length ; i++ )
  33.                 {
  34.                     newArray [i] = arr [i];
  35.                 }
  36.                 return newArray;
  37.             }
  38.  
  39.             else
  40.             {
  41.                 newArray = new int [1];
  42.                 newArray [0] = 0;
  43.                 return newArray;
  44.             }
  45.         }
  46.  
  47.         static int [] Add ( int [] arr )
  48.         {
  49.             int [] newArray = new int [arr.Length + 1];
  50.  
  51.             for ( int i = 0 ; i < newArray.Length ; i++ )
  52.             {
  53.                 if ( i < arr.Length )
  54.                 {
  55.                     newArray [i] = arr [i];
  56.                 }
  57.                 else
  58.                 {
  59.                     newArray [i] = 0;
  60.                 }  
  61.             }
  62.  
  63.             return newArray;
  64.         }
  65.  
  66.         static int [] Transfer ( int [] arr )
  67.         {
  68.             int [] newArray = new int [arr.Length];
  69.  
  70.             for ( int i = 0 ; i < newArray.Length ; i++ )
  71.             {
  72.                 newArray [i] = arr [i];
  73.             }
  74.             return newArray;
  75.         }
  76.     }
  77. }
Add Comment
Please, Sign In to add comment