代码

c代码

三位数

//1,2,3,4可以组成多少位不重复的三位数,并输出
#include <stdio.h>
int main()
{
	/*
	int g, s, b;
	int count = 0;
	for(b=1; b < 5; b++){
		for(s=1; s < 5; s++){
			for(g=1; g < 5; g++){
				if(b!=s && s!=g && g!=b){
					int three = b*100 + s*10 + g*1;
					printf("%d\n",three);
					count++;
					
				} 
				
				
			}
		}
	}
	printf("count=%d\n",count);
	*/
	//接下来进阶,0,1,2,3排列组合三位数,并输出多少位
	int b, s, g;
	int count = 0;
	for(b=1; b<4; b++){
		for(s=0; s<4; s++){
			for(g=0; g<4; g++){
				int three = b*100 + s*10 + g*1;
				if(b!=s && s!=g && g!=b){
					printf("%d\n", three);
					count++;	
				}
				
			} 
		} 		
	} 
	printf("count=%d\n", count);
	return 0;
 } 
  • 小技巧:三位数(n位数)的表示
posted @ 2022-10-15 17:22  行至为成  阅读(505)  评论(0)    收藏  举报