0
点赞
收藏
分享

微信扫一扫

C语言>>有1、2、3、4个数字,能组成多少个互不相同且无重复数字的三位数?都是多少?

梅梅的时光 2022-03-11 阅读 57

使用工具:

Dev-c++ 5.11

解题思路:

由题意可知一共有(A43)24种排列方案,写三层循环,全部遍历每一个数字(1、2、3、4)做百十个位的情况,然后再在最内层循环里面打印输出即可。

参考代码:

#include<stdio.h>
int main()
//排列组合 
{
 int count=0;
 for(int a=1;a<5;a++)
 {
 	for(int b=1;b<5;b++)
 	{
 		for(int c=1;c<5;c++)
 		{
 			if(a!=b && b!=c && c!=a)
 			{
			 count++;
 			printf("%d   ",a*100+b*10+c);
 			if(count%3==0) 
 		    	{
 				printf("\n");
			    }
	       	}
		 }
	 }
 }
	return 0;
}

运行结果:

 

举报

相关推荐

0 条评论