В вещественном массиве переписать в обратном порядке все положительные элементы - C#
Формулировка задачи:
Требуется помощь в решении данной проблемки.
Текст задания В вещественном массиве переписать в обратном порядке все положительные элементы. Остальные элементы массива оставить на прежних местах.
пока только сырость в виде :
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace progs { class Program { static void Main(string[] args) { int[] intArray = new int[] {3, 7, 0, -9, 10, 0, -12, 6, -5, 0, -14}; for (int i = 0; i < intArray.Length; i++) { Console.Write(" {0}",intArray[i]); } Console.WriteLine("\n"); for (int i = 0; i < intArray.Length; i++) { for (int j = 0; j < intArray.Length - 1; j++) { if (intArray[j + 1] > 0) { int k = intArray[j]; intArray[j] = intArray[j + 1]; intArray[j + 1] = k; } } } for (int i = 0; i < intArray.Length; i++) { Console.Write(" {0}", intArray[i]); } Console.WriteLine(); Console.ReadKey(); } } }
Решение задачи: «В вещественном массиве переписать в обратном порядке все положительные элементы»
textual
Листинг программы
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConApp1 { class Program { static void Main(string[] args) { int[] intArray = new int[] { 3, 7, 0, -9, 10, 0, -12, 6, -5, 0, -14 }; for (int k = 0; k < intArray.Length; k++) { Console.Write(" {0}", intArray[k]); } Console.WriteLine("\n"); int i = 0; int j = intArray.Length - 1; while (i < j) { while ((intArray[i] <= 0) && (i < j)) { i++; } while ((intArray[j] <= 0) && (i < j)) { j--; } int swap = intArray[i]; intArray[i] = intArray[j]; intArray[j] = swap; i++; j--; } for (int k = 0; k < intArray.Length; k++) { Console.Write(" {0}", intArray[k]); } Console.WriteLine("\n"); Console.ReadKey(); } } }
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д