454,440 Members | 1,420 Online Need help? Post your question and get tips & solutions from a community of 454,440 IT Pros & Developers. It's quick & easy.

# Generalizing a nested loop

 P: 5 I have a nested loop which generates ordered pairs, triplets, ... of integers from 0 to a maximum N. Expand|Select|Wrap|Line Numbers for ( a=0;a
7 Replies

 100+ P: 1,646 I have a nested loop which generates ordered pairs, triplets, ... of integers from 0 to a maximum N. Expand|Select|Wrap|Line Numbers for ( a=0;a

 P: 5 Yes they are different sorry for the confusion. N is just the maximum value allowed and n is the number of elements taken at a time 2,3,4... this is what I would like to make general. Dec 29 '06 #3

 100+ P: 1,646 Yes they are different sorry for the confusion. N is just the maximum value allowed and n is the number of elements taken at a time 2,3,4... this is what I would like to make general. OK. here you go Expand|Select|Wrap|Line Numbers    const int n = 3;    int a[n];    int N = 100;      for (int i = 0; i < n; i++)       a[i] = N - (i + 1); Dec 29 '06 #4

 P: 5 Thank you for your reply but that is not quite what I am looking for. I need all possiblities, as produced by this code for n=3 and N=5. If I want n=4 then I need to add an additional loop for ( a=0;a10 i would like to avoid. Expand|Select|Wrap|Line Numbers #include int main() {   const int n=3;   int N=5,a[n];     for ( a=0;a

 100+ P: 1,646 Thank you for your reply but that is not quite what I am looking for. I need all possiblities, as produced by this code for n=3 and N=5. If I want n=4 then I need to add an additional loop for ( a=0;a10 i would like to avoid. Expand|Select|Wrap|Line Numbers #include int main() {   const int n=3;   int N=5,a[n];     for ( a=0;a

 P: 5 I should have posted this code to begin, I need to make use of the values in each loop, not just the final loop. Dec 29 '06 #7

 P: 5 Well, I found a solution in a recursive function, the only thing I am not thrilled about is that instructions are now in the recursive function 'loop' after the else. Thanks willakawill for replying. Expand|Select|Wrap|Line Numbers #include   void loop(int a[], int n,int i){   for (a[i]=0;a[i] 