Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace _12.Middle_Elements
- {
- class Middle_Elements
- {
- static void Main(string[] args)
- {
- int[] array = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
- int[] newArray = new int[2];
- int[] newArray1 = new int[3];
- //int middleElement = 0;
- if (array.Length == 1)
- {
- Console.WriteLine("{0}",array[0]);
- }
- else
- {
- for (int i = 0; i < array.Length; i++)
- {
- if (array.Length % 2 == 0)
- {
- newArray[0] = array[array.Length / 2 - 1];
- newArray[1] = array[array.Length / 2];
- }
- else
- {
- newArray1[0] = array[array.Length / 2 - 1];
- newArray1[1] = array[array.Length / 2];
- newArray1[2] = array[array.Length / 2 + 1];
- }
- }
- if ((array.Length % 2 == 0))
- {
- Console.WriteLine(string.Join(", ", newArray));
- }
- else
- {
- Console.WriteLine(string.Join(", ", newArray1));
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement