Unit addition, sgp processing for unit Curtain Wall
If the input is an integer of 14, the running result is as follows:
# Include <stdio. h> int t; // the number of times I was repeat. // void divide (int I, int number) // {// int k, n = number; // while (n> I) // {// n = n-I; // if (n + I )! = Number) // {// for (k = 0; number-k> n; k = k + I) // printf ("% d +", I ); // printf ("% d \ n", n); //} // else // printf ("% d + % d \ n", I, n ); ///} //} void divide (int I, int n) {printf ("% d", I); for (int j = 0; j <t; j ++) {printf ("+ % d", I);} printf ("+ % d \ n", n-I ); if (n-I <= I) {return;} else {t ++; divide (I, n-I) ;}} int main () {int n; printf ("Input:"); scanf ("% d", & n); for (int I = 1; I <= n/2; I ++) {t = 0; divide (I, n) ;}return 0 ;}
If the input is an integer of 14, the running result is as follows:
// Recursion # include <stdio. h> int num (int a, int I, int n) {int j = 0, k; if (a <= 0) return a; k = num (a-I, i, n + I) + I; for (j = I; j <= n; j = j + I) printf ("% d +", I ); printf ("% d \ n", k); return k;} int main () {int number, n; printf ("input :"); scanf ("% d", & number); for (n = 1; n <= number/2; n ++) num (number-n, n, n ); return 0;} // non-recursive # include <stdio. h> void divide (int I, int num, int n) {int t, flag = 0; // t: indicates the number at the end if (n % I) {t = n % I; flag = 1;} else t = I; while (t <n) {for (int k = 0; k <num-1; k ++) {printf ("% d +", I);} if (flag) // {printf ("% d + % d \ n", I, t) ;}else {printf ("% d \ n", t) ;}t + = I; num -- ;}} int main () {int n; printf ("Input:"); scanf ("% d", & n); for (int I = 1; I <= n/2; I ++) divide (I, n/I, n); return 0 ;}