+ 1

Can someone explain me the array task

enter an array and a number L, create a new array from elements less than L

10th Dec 2022, 2:29 PM
Tripleks Cидик
Tripleks Cидик - avatar
7 Answers
+ 1
Если не упарыватся в динамические массивы, то просто 2 раза пройтись по введеному массиву. В первый раз мы считаем кол-во чисел меньше L, по найденому количеству объявляем новый массив и за второй заход заполняем его по условию задания
10th Dec 2022, 10:18 PM
Danila Khaminets
Danila Khaminets - avatar
+ 2
Read <L> value Let <smaller> = 0 Begin loop to read array elements Read element_value if element_value is less than <L> Increment <smaller> Save element_value into array End loop Create new array <result> reserved for <smaller> elements Begin loop to copy elements less than <L> for each element_value in array if element_value less than <L> Copy element_value into <result> End loop Call std::sort() from <algorithm> library, passing the array range, and `std::greater<data_type>()` as third argument. This will sort <result> in descending order.
11th Dec 2022, 4:33 PM
Ipang
+ 2
Thanks everyone for help, it really helped me, here's the code if someone interested int main() { const int n = 10; int i, L, m = 0, j = 0; int Arr[n]; int B[n]; int temp = 0; cout << " || Enter array with " << n << " valid numbers || \n"; for (i = 0; i < n; i++) cin >> Arr[i]; { cout << " || Enter L : || " << endl; cin >> L; } for (int i = 0; i < n; i++) if (Arr[i] < L) m++; for (int i = 0; i < n; i++) if (Arr[i] < L) B[j++] = Arr[i]; for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { if (B[i] < B[j]) { temp = B[i]; B[i] = B[j]; B[j] = temp; } } } cout << "Final array: "; for (int i = 0; i < m; i++) cout << B[i] << " "; system("pause"); return 0; }
11th Dec 2022, 9:29 PM
Tripleks Cидик
Tripleks Cидик - avatar
+ 1
Is that a task in SoloLearn? it didn't come so clear unfortunately. Add a link to the task in post Description if possible, so others can read it directly for better understanding.
10th Dec 2022, 3:10 PM
Ipang
+ 1
Предполагаю, что нужно из введенного массива в новый перенести просто все числа меньше L
10th Dec 2022, 9:47 PM
Danila Khaminets
Danila Khaminets - avatar
0
I found it in a programming book, so i just can paste full task, but it's in another language Full task: Enter an array and a number L, create a new array of elements smaller than L, and sort the new array in descending order The only thing i don't understand is how to create new array with smaller elements than L L it's just a random number
10th Dec 2022, 3:21 PM
Tripleks Cидик
Tripleks Cидик - avatar
0
Благодарю всевышно сударь, не подскажите как это можно осуществить?
10th Dec 2022, 10:05 PM
Tripleks Cидик
Tripleks Cидик - avatar