雨中登泰山优美句子:c语言排错

来源:百度文库 编辑:高考问答 时间:2024/05/04 18:57:18
题目:有1、2、3、4个数字,能组成多少个互不相同且无重复数字的三位数?
main()
{
int a,b,c;
int i=0;

for(a=1;a<5;a++)
{for(b=1;b<5&&b!=a;b++)
for(c=1;c<5&&c!=a&&c!=b;c++)
i++;
}
printf("i=%d",i);
}

楼主在for的循环条件里面写b!=a,这样的话,当b等于a时循环就结束了,而不去判断后面的数行不行。比如a=1时,b的循环条件一开始就不成立,那么b=2,3,4的情况都没有去尝试了。

这跟一个排列复合题差不多,但问题提得不够准确,1,2,3,4个数字???是1,2,3,4这四个数字呢?还是???
int pl(int top,int bottom){//排列
int tmp;
if(top>bottom){tmp=bottom;bottom=top;top=tmp;}
if(top<=0) return 1
else return bottom * pl(top-1,bottom-1);
}
int zuhu(int top,int bottom)
{
int tmp,topV,bottomV;
topV=0;bottomV=0;
if(top>bottom){tmp=bottom;bottom=top;top=tmp;}
if(top<=0 or bottom<=0) return 1;
if(top>bottom-top) top = bottom-top;//C(3,4)=C(1,4)减少程序运行时间
topV = pl(top,top);
bottomV = pl(bottom,bottom);
return topV/bottomV;
}

你想不明白!!
出错怎么解决
一.3 曾循环是对的
二.a++; b++; c++; 也很好
但是 一但出错就益处
&&b!=a 谁交你这么写的 ,这是if 下面的条件
比如
for(a=1;a<5;a++)
for(b=1;b<5;b++)
{if (b=a)
continue;
else
for(c=1;c<5;c++)
{
if(c=a&&c=b)
continue;
else
i++;
}
}
printf("i=%d",i);
}

main()
{
int a,b,c;
int i=0;

for(a=1;a<5;a++)
{
for(b=1;b<5;b++)
{
for(c=1;c<5;c++)
{
if(c!=a&&c!=b&&b!=a)i++;
}
}
}
printf("i=%d",i);
}

你的循环条件写的不对

main()