三层for循环嵌套实现代码
/*初学C语言,有不足还请指正*/
/*要求:有1,2,3,4四个数字
能组成多少个无重复数字的三位数*/
#include<stdio.h>
#include"math.h"
int main()
{
int a = 1;
int b = 1;
int c = 1;
int s = 0;
for (a = 1; a <= 4; a++)
{
if (a == b || a == c || b == c || a == b == c)
printf("");
else
{
printf("%d%d%d\n", a, b, c);
s = s + 1;
}
for (b = 1; b < 4; b++)
{
if (a == b || a == c || b == c || a == b == c)
printf("");
else
{
printf("%d%d%d\n", a, b, c);
s = s + 1;
}
for (c = 1; c < 4; c++)
{
if (a == b || a == c || b == c || a == b == c)
printf("");
else
{
printf("%d%d%d\n", a, b, c);
s = s + 1;
}
}
}
}
printf("一共有%d个这样的数", s);
}