用c语言实现输出全排列
时间: 2023-12-08 07:03:31 浏览: 103
```
#include <stdio.h>
void permute(int arr[], int start, int end)
{
if (start == end) {
for (int i = 0; i <= end; i++) {
printf("%d ", arr[i]);
}
printf("\n");
} else {
for (int i = start; i <= end; i++) {
int temp = arr[start];
arr[start] = arr[i];
arr[i] = temp;
permute(arr, start + 1, end);
temp = arr[start];
arr[start] = arr[i];
arr[i] = temp;
}
}
}
int main()
{
int arr[] = { 1, 2, 3 };
int n = sizeof(arr) / sizeof(arr[0]);
permute(arr, 0, n - 1);
return 0;
}
```
输出结果:
```
1 2 3
1 3 2
2 1 3
2 3 1
3 2 1
3 1 2
```
阅读全文