1412202059-hpu-1005:C语言考试练习题_排列

本文介绍了一道C语言编程练习题,题目要求使用四个不同的数字,输出所有可能的三数字组合排列。通过提供的示例输入和输出,展示了如何用C语言实现这一功能,并附带了完整的代码示例。

1005: C语言考试练习题_排列

Time Limit: 1 Sec   Memory Limit: 128 MB
Submit: 6   Solved: 2
[ Submit][ Status][ Web Board]

Description

有4个互不相同的数字,输出由其中三个不重复数字组成的排列。

Input

4个整数。

Output

所有排列。

Sample Input

1 2 3 4

Sample Output

1 2 3
1 3 2
2 1 3
2 3 1
3 1 2
3 2 1
1 2 4
1 4 2
2 1 4
2 4 1
4 1 2
4 2 1
1 3 4
1 4 3
3 1 4
3 4 1
4 1 3
4 3 1
2 3 4
2 4 3
3 2 4
3 4 2
4 2 3
4 3 2
解题思路
       通过观察输出可以发现题目所要求的输出规律。
代码
#include<stdio.h>
int num[5];
int main()
{
	int i,j,k;
	while(scanf("%d%d%d%d",&num[0],&num[1],&num[2],&num[3])!=EOF)
	{
		for(i=0;i<2;i++)
		    for(j=i+1;j<3;j++)
		        for(k=j+1;k<4;k++)
		        {
		        	printf("%d %d %d\n",num[i],num[j],num[k]);
		        	printf("%d %d %d\n",num[i],num[k],num[j]);
		        	printf("%d %d %d\n",num[j],num[i],num[k]);
		        	printf("%d %d %d\n",num[j],num[k],num[i]);
		        	printf("%d %d %d\n",num[k],num[i],num[j]);
		        	printf("%d %d %d\n",num[k],num[j],num[i]);
		        }
	}
	return 0;
} 


2025-08-08 12:44:16 192.168.65.1 - - [08/Aug/2025:04:44:16 +0000] "POST /console/api/apps/bb628330-da1c-45e8-8cc4-c98efc8fd03c/workflows/draft?_token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiNmY5NGY5MTUtYTUwOC00MDBlLWFmNjYtMDMyOTVmMjY4MTBiIiwiZXhwIjoxNzU0NjMxMzQ2LCJpc3MiOiJTRUxGX0hPU1RFRCIsInN1YiI6IkNvbnNvbGUgQVBJIFBhc3Nwb3J0In0.pPKcBIUA7k1jHu9cEEtf8gfdQCLRNWClP9yfbxZLqxg HTTP/1.1" 200 124 "http://localhost/app/bb628330-da1c-45e8-8cc4-c98efc8fd03c/workflow" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36" "-" 2025-08-08 12:44:17 2025/08/08 04:44:17 [notice] 10#10: using the "epoll" event method 2025-08-08 12:44:17 2025/08/08 04:44:17 [notice] 10#10: nginx/1.29.0 2025-08-08 12:44:17 2025/08/08 04:44:17 [notice] 10#10: built by gcc 12.2.0 (Debian 12.2.0-14+deb12u1) 2025-08-08 12:44:17 2025/08/08 04:44:17 [notice] 10#10: OS: Linux 6.6.16-linuxkit 2025-08-08 12:44:17 2025/08/08 04:44:17 [notice] 10#10: getrlimit(RLIMIT_NOFILE): 1048576:1048576 2025-08-08 12:44:17 2025/08/08 04:44:17 [notice] 10#10: start worker processes 2025-08-08 12:44:17 2025/08/08 04:44:17 [notice] 10#10: start worker process 19 2025-08-08 12:44:17 2025/08/08 04:44:17 [notice] 10#10: start worker process 20 2025-08-08 12:44:17 2025/08/08 04:44:17 [notice] 10#10: start worker process 21 2025-08-08 12:44:17 2025/08/08 04:44:17 [notice] 10#10: start worker process 22 2025-08-08 12:44:17 2025/08/08 04:44:17 [notice] 10#10: start worker process 23 2025-08-08 12:44:17 2025/08/08 04:44:17 [notice] 10#10: start worker process 24 2025-08-08 12:44:17 2025/08/08 04:44:17 [notice] 10#10: start worker process 25 2025-08-08 12:44:17 2025/08/08 04:44:17 [notice] 10#10: start worker process 26 2025-08-08 12:44:17 2025/08/08 04:44:17 [notice] 10#10: start worker process 27 2025-08-08 12:44:17 2025/08/08 04:44:17 [notice] 10#10: start worker process 28
最新发布
08-09
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值