Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- using namespace std;
- int a[15];
- int main()
- {
- int n, i, p;
- cin >> n;
- for(i = 1; i<= n; i++) a[i] = i;
- while(a[0] == 0)
- {
- for(i = 1; i <= n; i++) cout << a[i] << " ";
- cout << "\n";
- for(i = n; a[i] < a[i - 1]; i--);
- p = i - 1;
- for(i = p + 1; i <= n && a[p] < a[i]; i++);
- swap(a[p], a[i - 1]);
- sort(a + p + 1, a + n + 1);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment