Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. /*
  2. * Created by SharpDevelop.
  3. * User: stud_uiam13
  4. * Date: 22.3.2018
  5. * Time: 15:12
  6. *
  7. * To change this template use Tools | Options | Coding | Edit Standard Headers.
  8. */
  9. using System;
  10.  
  11. namespace cviko66
  12. {
  13. class Program
  14. {
  15. static void vypis(int [] pole)
  16. {
  17. Console.Write("Pole: ");
  18. for(int i = 0; i < pole.Length; i++)
  19. Console.Write(pole[i] + ", ");
  20.  
  21. Console.WriteLine();
  22. }
  23.  
  24. static int[] max(int[] pole)
  25. {
  26. int max = int.MinValue, max2 = int.MinValue;
  27.  
  28. for(int i = 0; i < pole.Length; i++){
  29. if(pole[i] > max)
  30. max = pole[i];
  31.  
  32. else if(pole[i] > max2)
  33. max2 = pole[i];
  34. }
  35.  
  36. int[] maxmax = new int[2];
  37. maxmax[0] = max;
  38. maxmax[1] = max2;
  39. return maxmax;
  40. }
  41.  
  42. static int[] max2(int[] pole)
  43. {
  44. Array.Sort(pole);
  45. //Array.Reverse(pole);
  46. int[] maxmax = new int[2];
  47. Array.Copy(pole, maxmax, 2);
  48.  
  49. return maxmax;
  50. }
  51.  
  52. public static void Main(string[] args)
  53. {
  54. Console.WriteLine("Zadaj dlzku pola");
  55. int n = Convert.ToInt32(Console.ReadLine());
  56. int[] pole = new int[n];
  57. Random rnd = new Random();
  58.  
  59. Console.WriteLine(pole[0]);
  60.  
  61. for(int i = 0; i < pole.Length; i++)
  62. pole[i] = rnd.Next(100);
  63.  
  64. vypis(pole);
  65. max(pole);
  66.  
  67. vypis(max(pole));
  68. vypis(max2(pole));
  69.  
  70. vypis(pole);
  71. Console.Write("Press any key to continue . . . ");
  72. Console.ReadKey(true);
  73. }
  74. }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement