View difference between Paste ID: L4uQz3ry and qEBGPYgE
SHOW: | | - or go back to the newest paste.
1
#include <stdio.h>
2
int mark[5];
3
int permuted[5];
4
int ara[] = {1, 2, 3, 4, 5};
5
void perm(int n)
6
{
7
    int i;
8
    for(i = 0; i<5; i++){
9
        if(mark[i]==0){
10
            permuted[n] = ara[i];
11
            mark[i] = 1;
12
            if(n==4){
13
                printf("%d %d %d %d %d\n", permuted[0], permuted[1], permuted[2], permuted[3], permuted[4]);
14
            }
15
            else perm(n+1);
16
            mark[i] = 0;
17
        }
18
    }
19
}
20
int main()
21
{
22
    perm(0);
23
	return 0;
24
}