0

program in c++ to rearrange the array in such a manner that all no.s divisible by 5 are stored first followed by the rest.

6th Jan 2018, 3:38 PM
Mukut Das
Mukut Das - avatar
2 ответов
+ 3
// If you can use built in functions... #include<iostream> #include<algorithm> using namespace std; int main() { int arr[5]={1,2,3,10,5}; sort(arr,arr+5, [](int a, int b)->bool {return a%5<=b%5&&a<b;}); for(int i:arr) cout<<i<<endl; // Prints 5,10,1,2,3. }
7th Jan 2018, 4:31 AM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar
+ 2
use some sorting algorithm and use your condition to sort it
6th Jan 2018, 4:36 PM
shobhit
shobhit - avatar