Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Created by SharpDevelop.
- * User: stud_uiam13
- * Date: 22.3.2018
- * Time: 15:12
- *
- * To change this template use Tools | Options | Coding | Edit Standard Headers.
- */
- using System;
- namespace cviko66
- {
- class Program
- {
- static void vypis(int [] pole)
- {
- Console.Write("Pole: ");
- for(int i = 0; i < pole.Length; i++)
- Console.Write(pole[i] + ", ");
- Console.WriteLine();
- }
- static int[] max(int[] pole)
- {
- int max = int.MinValue, max2 = int.MinValue;
- for(int i = 0; i < pole.Length; i++){
- if(pole[i] > max)
- max = pole[i];
- else if(pole[i] > max2)
- max2 = pole[i];
- }
- int[] maxmax = new int[2];
- maxmax[0] = max;
- maxmax[1] = max2;
- return maxmax;
- }
- static int[] max2(int[] pole)
- {
- Array.Sort(pole);
- //Array.Reverse(pole);
- int[] maxmax = new int[2];
- Array.Copy(pole, maxmax, 2);
- return maxmax;
- }
- public static void Main(string[] args)
- {
- Console.WriteLine("Zadaj dlzku pola");
- int n = Convert.ToInt32(Console.ReadLine());
- int[] pole = new int[n];
- Random rnd = new Random();
- Console.WriteLine(pole[0]);
- for(int i = 0; i < pole.Length; i++)
- pole[i] = rnd.Next(100);
- vypis(pole);
- max(pole);
- vypis(max(pole));
- vypis(max2(pole));
- vypis(pole);
- Console.Write("Press any key to continue . . . ");
- Console.ReadKey(true);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement