Advertisement
Guest User

Untitled

a guest
Sep 20th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.18 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text.RegularExpressions;
  5.  
  6. namespace Rextester
  7. {
  8.    
  9.     class S {
  10.         int []m = new int[5];
  11.         int max;
  12.         int min;
  13.            
  14.         public int this [int i]{
  15.             set { m[i] = value; }
  16.             get { return m[i]; }
  17.         }
  18.        
  19.         public int Max{
  20.             get { return max; }
  21.         }
  22.        
  23.         public int Min{
  24.             get { return min; }
  25.         }
  26.            
  27.         public void maxMin() {
  28.             max = min = m[0];
  29.             foreach (int i in m) {
  30.                 if (max < i) max = i;
  31.                 if (min > i) min = i;
  32.             }
  33.         }
  34.     }
  35.    
  36.     public class Program
  37.     {
  38.        
  39.         public static void Main(string[] args)
  40.         {
  41.             S s = new S();
  42.            
  43.             for (int i = 0; i < 5; i++) {
  44.                 s[i] = Convert.ToInt32(Console.ReadLine());
  45.             }
  46.             for (int i = 0; i < 5; i++) {
  47.                 Console.Write(s[i]+" ");
  48.             }
  49.             s.maxMin();
  50.             Console.Write("\nmax = {0}\nmin = {1}", s.Max, s.Min);
  51.         }
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement