#include <bits/stdc++.h>
using namespace std;
int n,m;
int arr[10];
bool isused[10];
void NM(int now_num) {
//base condition
if(now_num==m) {
for(int i=0; i<m; i++) {
cout << arr[i] << ' ';
}
cout << '\n';
return;
}
for(int i=1; i<=n; i++) {
if(!isused[i]) {
arr[now_num]=i;
isused[i]=1;
NM(now_num+1);
isused[i]=0;
}
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
NM(0);
return 0;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: