如果你想知道具体有哪些数的话……
程序代码:
#include <stdio.h> #define swap(x,y) {char _t=x; x=y; y=_t; } char a[10] = "01234567"; int n = 8, c = 0; void dfs(int k) { int i; if (k == n) { if (a[n-1] % 2) { puts(a); c++; } return; } if (k != 0 || a[0] != '0') dfs(k + 1); for (i = k + 1; i < n; i++) { swap(a[k], a[i]); dfs(k + 1); swap(a[k], a[i]); } } int main() { dfs(0); printf("Count = %d\n", c); return 0; }