I have a problem on my book, he wants me to build a program that will print all possible combinations (N-1) that the sum of them will be N.
I have this code as far:
I can't understand what to do next, don't make me the code, just try to explain me how to do it.Code:#include <stdio.h> #include <stdlib.h> void recur(int n); //our recursive function int main(void) { int nNum; //get data, check it and act printf("Insert a number: "); if(!scanf("%d",&nNum)) { printf("Invalid input\n"); exit(1); } //call ou recursive function recur(nNum); //pause and exit system("PAUSE"); return 0; } void recur(int n) { if(n == 0) return; else if(n == 1) { printf("1"); return; } else if(n == 2) { printf("11"); return; } else { printf("1"); recur(n-1); } }
Hmm, I cannot use any static variables or loops in the recursive function.
Thanks.