static void Main(string[] args) { int[] myArray = InteractiveWithUser.GetIntArray(); int evenElements = 0; int oddElements = 0; for (int i = 0; i < myArray.Length; i++) { if (myArray[i] % 2 == 0) { evenElements++; } else { oddElements++; } } int[] evenArray = new int[evenElements]; int[] oddArray = new int[oddElements]; int j = 0; int k = 0; for (int i = 0; i < myArray.Length; i++) { if (myArray[i] % 2 == 0) { evenArray[j] = myArray[i]; j++; } } for (int i = 0; i < myArray.Length; i++) { if (myArray[i] % 2 != 0) { oddArray[k] = myArray[i]; k++; } } Console.Write("Parzyste liczby to: "); for (int i = 0; i < evenArray.Length; i++) { Console.Write(evenArray[i] + " "); } Console.Write("\n"); Console.Write("Nieparzysteliczby to: "); for (int i = 0; i < oddArray.Length; i++) { Console.Write(oddArray[i] + " "); } Console.ReadLine(); }
static void Main(string[] args) { int[] firstArray = InteractiveWithUser.GetIntArray(); List <int> firstList = new List <int>(); for (int i = 0; i < firstArray.Length; i++) { firstList.Add(firstArray[i]); } int inputIndex = InteractiveWithUser.GetIntFromUser("Wprowadź Index "); Console.WriteLine("Przed usunięciem "); Console.WriteLine("\n"); for (int i = 0; i < firstList.Count; i++) { Console.Write(firstList[i] + " "); } firstList.RemoveAt(inputIndex); Console.WriteLine("Po usunięciu "); Console.WriteLine("\n"); for (int i = 0; i < firstList.Count; i++) { Console.Write(firstList[i] + " "); } Console.ReadLine(); }
static void Main(string[] args) { int[] firstArray = InteractiveWithUser.GetIntArray(); firstArray = Sorting.sortingByDescending(firstArray, 1); Console.ReadLine(); }
static void Main(string[] args) { int[] firstArray = InteractiveWithUser.GetIntArray(); firstArray = Sorting.sortingByAscending(firstArray); Console.WriteLine("Druga najmniejsza liczba to " + firstArray[1]); Console.ReadLine(); }
static void Main(string[] args) { int[] firstArray = InteractiveWithUser.GetIntArray(); Array.Sort(firstArray); int length = firstArray.Length; Console.WriteLine("Najmniejsza liczba to " + firstArray[0]); Console.WriteLine("Największa liczba to " + firstArray[length - 1]); Console.ReadLine(); }
static void Main(string[] args) { List <int> firstList = new List <int>(); int[] firstArray = InteractiveWithUser.GetIntArray(); firstArray = Sorting.sortingByAscending(firstArray); for (int i = 0; i < firstArray.Length; i++) { firstList.Add(firstArray[i]); } int insertedNumber = InteractiveWithUser.GetIntFromUser(); int numberOfIndex = 0; for (int i = 0; i < firstArray.Length; i++) { if (insertedNumber >= firstArray[firstArray.Length - 1]) { numberOfIndex = firstArray.Length; break; } else if (insertedNumber > firstArray[i]) { continue; } else if (insertedNumber < firstArray[0]) { numberOfIndex = 0; break; } else { numberOfIndex = i; } } firstList.Insert(numberOfIndex, insertedNumber); Console.WriteLine("\n"); Console.WriteLine("Oto nowy ciąg "); for (int i = 0; i < firstList.Count; i++) { Console.Write(firstList[i] + " "); } Console.ReadLine(); }
static void Main(string[] args) { int[] firstArray = InteractiveWithUser.GetIntArray(); Array.Sort(firstArray); Console.WriteLine("Elementy posortowane rosnąco"); for (int i = 0; i < firstArray.Length; i++) { Console.Write(firstArray[i] + " "); } Console.ReadLine(); }
static void Main(string[] args) { int[] arrayFromUser = InteractiveWithUser.GetIntArray(); int NumberOfLoops = arrayFromUser.Length; if (NumberOfLoops <= 0) { Console.WriteLine("Brak tablicy od użytkownika"); } else { bool[] differentValuesOfArray = new bool[NumberOfLoops]; for (int i = 0; i < NumberOfLoops; i++) { if (differentValuesOfArray[i] == true) { continue; } else { for (int j = 0; j < NumberOfLoops; j++) { if (i == j) { continue; } if (arrayFromUser[i] == arrayFromUser[j]) { differentValuesOfArray[i] = true; differentValuesOfArray[j] = true; } } } } Console.WriteLine("----------------------"); for (int i = 0; i < NumberOfLoops; i++) { if (differentValuesOfArray[i] == false) { Console.WriteLine(arrayFromUser[i]); } } } Console.ReadLine(); }
static void Main(string[] args) { int[] firstArrayFromUser = InteractiveWithUser.GetIntArray(); int[] secoundArrayFromUser = InteractiveWithUser.GetIntArray(); int totalArrayLength = firstArrayFromUser.Length + secoundArrayFromUser.Length; int[] thirdArrayFromUser = new int[totalArrayLength]; for (int i = 0; i < totalArrayLength; i++) { if (i < firstArrayFromUser.Length) { thirdArrayFromUser[i] = firstArrayFromUser[i]; } else if (i >= firstArrayFromUser.Length) { thirdArrayFromUser[i] = secoundArrayFromUser[i - firstArrayFromUser.Length]; } } Console.WriteLine("--------------"); for (int i = 0; i < thirdArrayFromUser.Length; i++) { Console.Write(thirdArrayFromUser[i] + " "); } Array.Sort(thirdArrayFromUser); Console.Write("\n"); for (int i = 0; i < thirdArrayFromUser.Length; i++) { Console.Write(thirdArrayFromUser[i] + " "); } Console.ReadLine(); }
static void Main(string[] args) { int[] firstArray = InteractiveWithUser.GetIntArray(); List <int> firstList = new List <int>(firstArray.Length + 1); for (int i = 0; i < firstArray.Length; i++) { firstList.Add(firstArray[i]); } firstArray = Sorting.sortingByAscending(firstArray); int inputValue = InteractiveWithUser.GetIntFromUser(); int inputIndex = InteractiveWithUser.GetIntFromUser("Wprowadź index"); Console.WriteLine("Przed dodaniem wartości"); Console.WriteLine("\n"); for (int i = 0; i < firstList.Count; i++) { Console.Write(firstList[i] + " "); } firstList.Insert(inputIndex, inputValue); Console.WriteLine("\n"); Console.WriteLine("Po dodaniu wartości"); Console.WriteLine("\n"); for (int i = 0; i < firstList.Count; i++) { Console.Write(firstList[i] + " "); } Console.ReadLine(); }
static void Main(string[] args) { int[] arrayFromUser = InteractiveWithUser.GetIntArray(); int lengthOfArrayFromUser = arrayFromUser.Length; int[] amountOfNumbersInArray = new int[lengthOfArrayFromUser]; for (int i = 0; i < lengthOfArrayFromUser; i++) { amountOfNumbersInArray[i] += 1; } for (int i = 0; i < lengthOfArrayFromUser; i++) { for (int j = 0; j < lengthOfArrayFromUser; j++) { if (i == j) { continue; } else if (arrayFromUser[i] == arrayFromUser[j] && amountOfNumbersInArray[i] > 1) { amountOfNumbersInArray[i]++; } else if (arrayFromUser[i] == arrayFromUser[j]) { amountOfNumbersInArray[i]++; } } } int[] secoundArrayFromUser = new int[lengthOfArrayFromUser]; //Przypisanie do 2 tablicy for (int i = 0; i < lengthOfArrayFromUser; i++) { secoundArrayFromUser[i] = arrayFromUser[i]; } Array.Sort(secoundArrayFromUser); for (int i = 0; i < lengthOfArrayFromUser; i++) { arrayFromUser[i] = 0; } for (int i = 0; i < lengthOfArrayFromUser; i++) { for (int j = 0; j < i; j++) { if (secoundArrayFromUser[i] == secoundArrayFromUser[j]) { continue; } else { Console.WriteLine(secoundArrayFromUser[i] + " wystąpiło " + amountOfNumbersInArray[i] + " razy"); } } } Console.ReadLine(); }