Pagini recente » Cod sursa (job #1212085) | Istoria paginii runda/simulare_oji_2023_clasele_11_12_16_martie3/clasament | Cod sursa (job #2713396) | Cod sursa (job #1165624) | Cod sursa (job #1429568)
#include <stdio.h>
short N, a[10];
FILE* f;
FILE* g;
void back(int n, int pos)
{
for (int i = 1; i <= N; ++i)
{
bool x = false;
for (int o = 0; o < pos; ++o)
if (a[o] == i)
x = true;
if (!x)
{
a[pos] = i;
if (pos < N - 1)
{
back(n, pos + 1);
}
else
{
for (int k = 0; k < N; k++)
{
fprintf(g, "%d ", a[k]);
}
fprintf(g, "\n");
}
}
}
}
int main()
{
f = fopen("permutari.in", "r");
g = fopen("permutari.out", "w");
fscanf(f, "%d", &N);
back(N, 0);
return 0;
}