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. | SoloLearn: Learn to code for FREE!

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.

c++

1/6/2018 3:38:29 PM

Mukut Das

2 Answers

New Answer

+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. }

+2

use some sorting algorithm and use your condition to sort it