有0、1、2、4这4个数字,能组成多少个互不相同且个位、十位、百位数之和为4的三位数(各位可以相同)?都是多少? 输出格式为:先输出有多少个,再依次输出各个数
求助大佬有0、1、2、4这4个数字,能组成多少个互不相同且个位、十位、百位数之和为4的三位数(各位可以相同)?都是多少?
C语言输出格式为:先输出有多少个,再依次输出各个数,数之间以空格隔开。
#include <stdio.h> int main( void ) { for( unsigned i=4*4; i!=4*4*4; ++i ) { unsigned a = (i/16)*4/3; unsigned b = (i/4%4)*4/3; unsigned c = (i%4)*4/3; if( a+b+c == 4 ) printf( "%u%u%u\n", a, b, c ); } }