+ 1
Can someone explain me the array task
enter an array and a number L, create a new array from elements less than L
7 Answers
+ 1
Если не упарыватся в динамические массивы, то просто 2 раза пройтись по введеному массиву. В первый раз мы считаем кол-во чисел меньше L, по найденому количеству объявляем новый массив и за второй заход заполняем его по условию задания
+ 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.
+ 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;
}
+ 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.
+ 1
Предполагаю, что нужно из введенного массива в новый перенести просто все числа меньше L
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
0
Благодарю всевышно сударь, не подскажите как это можно осуществить?