Removal of array elements- instruction
Domain: arrays, transforming arrays
Load a set of integers of n elements.
Through the do-while loop, repeat the process of removing unwanted elements from the current copy of the array obtained after the removed elements in previous iterations,
As a condition for repetition, it can be a logical variable that is set to false before each of these iterations. If no element is removed in the removal process, then the logical variable will remain false, otherwise, if at least one element is removed, then it will be set to true.
The procedure in one iteration of this to loop, where the undesirable element is removed:
through the loop, take the current element of the string a [i] and check whether this element of the partition of the number of elements of the sequence m is.
If it is divisible, it is noted that it has removal elements and skips the current iteration for the cycle.
If it is not divisible then this element is preferred and it is copied into the second array b.
if(m % a[ i ] == 0)
{
hasAnyElements=true;
continue;
}
else
{
b[j++]=a[ i ];
// cout<<b[j-1]<<" ";
}
After passing and testing all the elements of the array, and in the row b, there will be only desirable elements. For example.
int a [10] = {2,3,4,5,6,7,8,9,10};
Since m = 9 (number of elements) in this series, undesirable members are 3 and 9 because they are partitions of number 9. Array b would be composed of numbers:
2,4,5,6,7,8
Since it was undesirable, it goes to the next iteration in to the loop. Now it is m = 7, and the array for the next iteration should be what is in the current iteration array b.
Before the next iterations, the sequence b in the array a should be copied:
for(int i=0;i<m;i++){
a[i]=b[i];
}
In the second iteration to loop only 7 is removed, so the sequence and after the end of the cycle (after rewriting the string b again into the array a):
2,4,5,6,8
After the 3rd iteration m = 5, and the element 5:
2,4,6,8
After the 4th iteration m = 4, and the elements 2 and 4 are removed:
6.8
now m = 2.
Of these elements, no one is a divisor of number 2, and now ends outside to loop
Through the do-while loop, repeat the process of removing unwanted elements from the current copy of the array obtained after the removed elements in previous iterations,
As a condition for repetition, it can be a logical variable that is set to false before each of these iterations. If no element is removed in the removal process, then the logical variable will remain false, otherwise, if at least one element is removed, then it will be set to true.
The procedure in one iteration of this to loop, where the undesirable element is removed:
through the loop, take the current element of the string a [i] and check whether this element of the partition of the number of elements of the sequence m is.
If it is divisible, it is noted that it has removal elements and skips the current iteration for the cycle.
If it is not divisible then this element is preferred and it is copied into the second array b.
if(m % a[ i ] == 0)
{
hasAnyElements=true;
continue;
}
else
{
b[j++]=a[ i ];
// cout<<b[j-1]<<" ";
}
After passing and testing all the elements of the array, and in the row b, there will be only desirable elements. For example.
int a [10] = {2,3,4,5,6,7,8,9,10};
Since m = 9 (number of elements) in this series, undesirable members are 3 and 9 because they are partitions of number 9. Array b would be composed of numbers:
2,4,5,6,7,8
Since it was undesirable, it goes to the next iteration in to the loop. Now it is m = 7, and the array for the next iteration should be what is in the current iteration array b.
Before the next iterations, the sequence b in the array a should be copied:
for(int i=0;i<m;i++){
a[i]=b[i];
}
In the second iteration to loop only 7 is removed, so the sequence and after the end of the cycle (after rewriting the string b again into the array a):
2,4,5,6,8
After the 3rd iteration m = 5, and the element 5:
2,4,6,8
After the 4th iteration m = 4, and the elements 2 and 4 are removed:
6.8
now m = 2.
Of these elements, no one is a divisor of number 2, and now ends outside to loop
© 2019 by Slobodan izprogramiranja.weebly.com
All rights reserved