cOMBINATIONS!

i HAVE THIS PROGRAM FROM MY TEACHER AND I HAVE TO EXPLAIN STEP BY STEP WHAT IS HE DOING.i REALLY NEED SOME HELP BEACUSE I DON'T KNOW VERY WEEL.tHX.

#include <iostream>
//#include <stdio.h>
using namespace std;

int a[20],b[20];

void aranjamente(int k, int len, int max){
if(k-1 == max){
for(int i = 1; i <= max; i++)
cout << a[i];
cout << endl;
}
else{
for(int i = 1; i <= len; i++)
if(!b[i]){
a[k] = i;
b[i] = 1;
aranjamente(k+1, len, max);
b[i] = 0;
}
}
}

int main(){
int n,k;
cin >> n;
cin >> k;
aranjamente(1, n, k);
return 0;
}
did you use a debugger on this yet? if not, do it now.
Did you really write all this not knowing you had caps lock on?
1/4th of an inch.
That is the distance you would have to move your finger in order to reach the caps lock button.

Use the debugger, step through the program.
Also, have the program output variables on each loop so you can see what they're doing.
Then you should get a better idea of what the program is doing, as the function isn't very descriptive of itself.
Topic archived. No new replies allowed.