#include <iostream>
using namespace std;

#define N 5
#define M 2
int data[] = {1, 2, 3, 4, 5};
int len = N;
int count = 0;

void swap(int &a, int &b)
{
    int temp = a;
    a = b;
    b = temp;
}

void permutation(int* arr, int n, int m)
{
    int i;
    if (m == 0)
    {
        ++count;
        for (i = 0; i < M; ++i)
        {
            cout << data[i] << " ";
        }
        cout << endl;
        return;
    }
    for (i = 0; i < n; ++i)
    {
        swap(arr[i], arr[0]);
        permutation(arr + 1, n – 1, m – 1);
        swap(arr[i], arr[0]);
    }
}

Advertisements