Skip to content

Commit

Permalink
recursion
Browse files Browse the repository at this point in the history
  • Loading branch information
DanSizov committed Apr 20, 2023
1 parent f341115 commit 219dd8f
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions combination/Source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,21 @@ namespace ask {

return number;
}

void combination(int* array, int size, int i, int j) {

if (i >= size) {
return;
}

if (j >= size) {
combination(array, size, i + 1, i + 2);
return;
}

std::cout << array[i] << " , " << array[j] << std::endl;
combination(array, size, i, j + 1);
}
}

int main() {
Expand All @@ -23,16 +38,8 @@ int main() {
array[i] = i + 1;
}

for (int i = 0; i < size; i++) {

for (int j = 1; j < size; j++) {

if (array[j] > array[i]) {

std::cout << array[i] << " , " << array[j] << std::endl;
}
}
}
ask::combination(array, size, 0, 1);

delete[] array;
return EXIT_SUCCESS;
}

0 comments on commit 219dd8f

Please sign in to comment.