Advertisement
wingman007

FindMinMax

Sep 18th, 2016
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.87 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 MinMaxArray
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int[] myArray = { 1,2,3,4,5,6,7,8};
  14.             Console.WriteLine("Min {0}", FindMin(myArray));
  15.             Console.WriteLine("Max {0}", FindMax(myArray));
  16.         }
  17.  
  18.         static int FindMin(int[] a)
  19.         {
  20.             int min = a[0];
  21.             for (int i = 0; i < a.Length; i++)
  22.             {
  23.                 if (a[i] < min) min = a[i];
  24.             }
  25.             return min;
  26.         }
  27.  
  28.         static int FindMax(int[] a)
  29.         {
  30.             int min = a[0];
  31.             for (int i = 0; i < a.Length; i++)
  32.             {
  33.                 if (a[i] > min) min = a[i];
  34.             }
  35.             return min;
  36.         }
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement