0

Make a program

Hey there 👋! Can you make a program which does sorting array.. not general sorting Input format : 2,3,5,7,9 Output : 3,5,7,9,2 5,7,9,2,3 7,9,2,3,5 9,2,3,5,7 2,3,5,7,9 Like this.. I am sorry for small description.. I didn't find it in any web or app.. It came in my mind, I tried, failed and now asking help from you guys.. If you need more informations, tell me.

27th Apr 2021, 4:30 PM
Mohammad Mehedi Hasan
Mohammad Mehedi Hasan - avatar
2 Answers
+ 3
#include <iostream> #include <vector> using namespace std; int main() { vector<int> v{2,3,5,7,9}; vector<vector<int>> a; for(int i = 0; i < v.size(); i++){ vector<int> tm; for(int j = 1; j < v.size(); j++){ tm.push_back(v[j]); } tm.push_back(v[0]); a.push_back(tm); v = tm; } for(int i = 0; i < a.size(); i++){ for(int j = 0; j < a.size(); j++){ cout << a[i][j] << " "; } cout << endl; } return 0; }
27th Apr 2021, 4:50 PM
minirkk
minirkk - avatar