CryptoJones

InteviewQuestionForReddit

Jun 15th, 2018
406
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. static void Main(string[] args)
  2. {
  3.  
  4. int[] myArray = new int[] {2, 4, 8, 16, 32, 64, 128, 256};
  5.  
  6. Console.WriteLine(GetMaxAndMin(myArray));
  7. Console.ReadLine();
  8. }
  9.  
  10. static string GetMaxAndMin(int[] array)
  11. {
  12.  
  13. int min = array[0];
  14. int max = array[0];
  15.  
  16. foreach (int n in array)
  17. {
  18. if (min > n) {
  19. min = n;
  20. }
  21.  
  22. if (max < n)
  23. {
  24. max = n;
  25. }
  26.  
  27. }
  28.  
  29. return "Min = " + min + ", Max = " + max + ".";
  30. }
  31. }
Add Comment
Please, Sign In to add comment