fork download
  1. using System;
  2.  
  3.  
  4.  
  5. public class Test
  6.  
  7. {
  8.  
  9. static int MaxVal(int[] intArray)
  10.  
  11. {
  12.  
  13. int maxVal = intArray[0];
  14.  
  15. for (int i = 1; i < intArray.Length; i++)
  16.  
  17. {
  18.  
  19. if (intArray[i] > maxVal)
  20.  
  21. maxVal = intArray[i];
  22.  
  23. }
  24.  
  25. return maxVal;
  26.  
  27. }
  28.  
  29.  
  30.  
  31. public static void Main()
  32.  
  33. {
  34.  
  35. int[] miArreglo = { 1, 8, 3, 6, 2, 5, 9, 0, 2 };
  36.  
  37. int maxValor = MaxVal(miArreglo);
  38.  
  39. Console.WriteLine("El valor máximo del arreglo es: {0}", maxValor);
  40.  
  41. }
  42.  
  43. }
Success #stdin #stdout 0.06s 28816KB
stdin
Standard input is empty
stdout
El valor máximo del arreglo es: 9