void combSort(int arr[], int n) { int gap = n; float shrink = 1.3; bool swapped = true;
while (gap > 1 || swapped) { if (gap > 1) { gap /= shrink; } swapped = false; for (int i = 0; gap + i < n; i++) { if (arr[i] > arr[i + gap]) { swap(arr[i], arr[i + gap]); swapped = true; } } }
}
int main() { int n; cout << "Enter the number of elements in the array: "; cin >> n;
int arr[n]; cout << "Enter the elements of the array: "; for (int i = 0; i < n; i++) { cin >> arr[i]; } combSort(arr, n); cout << "Sorted array: "; for (int i = 0; i < n; i++) { cout << arr[i] << " "; } return 0;
using namespace std;
void combSort(int arr[], int n) {
while (gap > 1 || swapped) {int gap = n;
float shrink = 1.3;
bool swapped = true;
if (gap > 1) {
gap /= shrink;
}
swapped = false;
for (int i = 0; gap + i < n; i++) {
if (arr[i] > arr[i + gap]) {
swap(arr[i], arr[i + gap]);
swapped = true;
}
}
}
}
int main() {
int arr[n];int n;
cout << "Enter the number of elements in the array: ";
cin >> n;
cout << "Enter the elements of the array: ";
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
combSort(arr, n);
cout << "Sorted array: ";
for (int i = 0; i < n; i++) {
cout << arr[i] << " ";
}
return 0;
}