C language: There are 1, 2, 3, and 4 numbers. How many different three-digit numbers can be formed without repeated numbers?

#include <stdio.h>
int main(){
    int i,j,k,t;
    int count=0;
    printf("they are as follows:\n");
    for(t=0,i=1;i<=4;i++)//百位数字有4种选择
        for(j=1;j<=4;j++)//十位数字有3种选择
            if(j!=i)//遇到十位数字等于百位数字时跳过
                for(k=1;k<=4;k++)//个位数字只有2种选择了
                    if(k!=i && k!=j)//个位数字与十位或百位数字相等时跳过
                       {
					    count++;
						printf(++t%10 ? "%4d" : "%4d\n",i*100+j*10+k);//输出该三位数
				}
    if(t%10)
        printf("\n");
    
        printf("have %d number",count);
    return 0;
}

Guess you like

Origin blog.csdn.net/samxiaoguai/article/details/78598212