求和为某数的全部组合
在给定数字范围内,求和为某数的全部组合
#include <stdio.h> struct Zhan{ int n; int content[100]; }; ruZhan(struct Zhan* zhan, int x){ (*zhan).content[(*zhan).n] = x; (*zhan).n++; } czZhan(struct Zhan* zhan, int n){ (*zhan).n = n; } printfZhan(struct Zhan* zhan){ int i; for(i = 0; i < (*zhan).n; i++){ printf("%d ", (*zhan).content[i]); } printf("\n"); } int find(int e, int x, struct Zhan* zhan){ int n; n = (*zhan).n; if(e <= 0) return 0; if(x - e > 0){ ruZhan(zhan, e); find(e - 1, x - e, zhan); } else if(x - e < 0) ; else if(x - e == 0){ ruZhan(zhan, e); printfZhan(zhan); } czZhan(zhan, n); find(e - 1, x, zhan); } main(){ struct Zhan zhan; zhan.n = 0; find(100, 41, &zhan); printfZhan(&zhan); }