Advertisement
Maxim_Kuraksin

MinMaxValues

Nov 1st, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.24 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace MinMaxValues
  8. {
  9.     class IntArray
  10.     {
  11.         int i;
  12.  
  13.         public int[] array;
  14.  
  15.         public readonly int maxValue = int.MinValue;
  16.         public readonly int minValue = int.MaxValue;
  17.  
  18.         public int this[int index]
  19.         {
  20.             get
  21.             {
  22.                 return array[index];
  23.             }
  24.  
  25.             set
  26.             {
  27.                 array[index] = value;
  28.             }
  29.         }
  30.  
  31.         public IntArray(int[] newArray)
  32.         {
  33.             array = new int[newArray.Length];
  34.             for (i = 0; i < newArray.Length; i++)
  35.             {
  36.                 array[i] = newArray[i];
  37.                 if (array[i] > maxValue)
  38.                 {
  39.                     maxValue = array[i];
  40.                 }
  41.                 if (array[i] < minValue)
  42.                 {
  43.                     minValue = array[i];
  44.                 }
  45.             }
  46.  
  47.         }
  48.  
  49.         public void PrintArray()
  50.         {
  51.             for (i = 0; i < array.Length; i++)
  52.                 Console.Write(array[i] + " ");
  53.         }
  54.  
  55.        
  56.     }
  57.     class Program
  58.     {
  59.         static void Main(string[] args)
  60.         {
  61.             int i = 0;
  62.             int N = 0;
  63.  
  64.             Console.Write("Количество элементов массива: ");
  65.             N = Convert.ToInt32(Console.ReadLine());
  66.  
  67.             int[] externalArray = new int[N];
  68.  
  69.             Console.WriteLine("\nВведите элементы массива:");
  70.  
  71.             for (i = 0; i < externalArray.Length; i++)
  72.             {
  73.                 Console.Write("{0} элемент: ", i + 1);
  74.                 externalArray[i] = Convert.ToInt32(Console.ReadLine());
  75.             }
  76.  
  77.             IntArray firstObject = new IntArray(externalArray);
  78.  
  79.             Console.WriteLine("\nВведенный массив:");
  80.  
  81.             firstObject.PrintArray();
  82.  
  83.             Console.WriteLine("\n\nМаксимальный элемент: {0}", firstObject.maxValue);
  84.             Console.WriteLine("Минимальный элемент: {0}", firstObject.minValue);
  85.  
  86.             Console.ReadKey(true);
  87.         }
  88.     }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement