C语言经典100例 练习实例1

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


代码如下:

#include <stdio.h>
int main()
{
	int a,b,c,count=0;;
	for(a=1;a<=4;a++)
	{
		for(b=1;b<=4;b++)
		{
			for(c=1;c<=4;c++)
			{

				if(a!=b && a!=c && b!=c){
					count++;
					printf("%d\n",a*100+b*10+c*1);   	
				}		
			}
		}
	}
	printf("%d",count);
} 


结果:
123
124
132
134
142
143
213
214
231
234
241
243
312
314
321
324
341
342
412
413
421
423
431
432
24


猜你喜欢

转载自blog.csdn.net/xiaodingqq/article/details/80293616
今日推荐