/* 题目:有1、2、3、4个数字,能组成多少个互不相同且无重复数字的三位数?都是多少? */ #include<stdio.h> int p(int, const int *, int); int b(int ); int main(void) { int num[4]={1, 2, 3, 4}; int i, n; i = n = 0; for(i=123;i<=432;i++){ if(p(i,num,4)&&b(i)){ printf("%d\t", i); n++; } } printf("\n可以组合出%d个数\n", n); return 0; } /*判断 ‘个‘, ‘十‘, ‘百‘每个位是否属于这四个数. */ int p(int cup, const int *cat, int n) { int bowle, i, renum; while(cup>=10){ bowle = cup%10; cup /= 10; for(i=0;i<n;i++){ if(bowle == cat[i]){ renum = 1; break; } else renum = 0; } if(renum==0) break; } return renum; } /*判断 个,十,百 每位都不重叠.*/ int b(int num) { int bowle[3] ={0}; int i = 0; while(num>=10){ bowle[i] = num%10; num /= 10; i++; } bowle[i] = num; return bowle[0]!=bowle[1]&&bowle[0]!=bowle[2]&&bowle[1]!=bowle[2]; }
时间: 2024-09-29 02:23:53