qfedu-c-level/day6/homework/h5.c

39 lines
896 B
C
Raw Permalink Normal View History

2023-07-11 01:33:28 +08:00
// 编写程序键盘输入5个整数输出它们的所有排列组合
#include <stdio.h>
void fun1(int *nums);
int main()
{
int nums[5];
printf("请输入 5 个整数: ");
int i = 0;
while (i < 5)
{
scanf("%d", &nums[i++]);
}
// 笨办法
fun1(nums);
return 0;
}
void fun1(int *nums)
{
int a, b, c, d, e;
for (a = 0; a < 5; a++)
for (b = 0; b < 5; b++)
for (c = 0; c < 5; c++)
for (d = 0; d < 5; d++)
for (e = 0; e < 5; e++)
if (
a != b && a != c && a != d && a != e &&
b != c && b != d && b != e &&
c != d && c != e &&
d != e)
printf("%d%d%d%d%d\n", nums[a], nums[b], nums[c], nums[d], nums[e]);
return;
}