循环遍历即可。if (i != j && j !=k && k!=i) 。
三种不同颜色的条件#include <stdioh>#include <stdlibh>void main(){int i,j,k,n=0;char c[5][7]={"red","yellow","blue","white","black"};for (i=0;i<5;i++)for (j=i+1;j<5;j++)for (k=j+1;k<5;k++){ if (i != j && j !=k && k!=i) printf("%s %s %s\n",c[i],c[j],c[k]); n++;}。
printf("n=%d",n);}得:red yellow bluered yellow whitered yellow blackred blue whitered blue blackred white blackyellow blue whiteyellow blue blackyellow white blackblue white blackn=10
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)