#include <iostream>
using namespace std;
int main() {
int n;
// Ask for the number of elements
cout << "Enter the number of elements: ";
cin >> n;
// Declare an array of size n
int arr[n];
// Input the elements of the array
cout << "Enter the elements:" << endl;
for(int i = 0; i < n; i++) {
cin >> arr[i];
}
// Bubble Sort Algorithm to sort the array in descending order
for(int i = 0; i < n - 1; i++) {
for(int j = 0; j < n - 1 - i; j++) {
if(arr[j] < arr[j + 1]) {
// Swap the elements if they are in the wrong order (for descending order)
int temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
// Display the sorted array in descending order
cout << "Sorted elements in descending order: ";
for(int i = 0; i < n; i++) {
cout << arr[i] << " ";
}
cout << endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50IG1haW4oKSB7CiAgICBpbnQgbjsKCiAgICAvLyBBc2sgZm9yIHRoZSBudW1iZXIgb2YgZWxlbWVudHMKICAgIGNvdXQgPDwgIkVudGVyIHRoZSBudW1iZXIgb2YgZWxlbWVudHM6ICI7CiAgICBjaW4gPj4gbjsKCiAgICAvLyBEZWNsYXJlIGFuIGFycmF5IG9mIHNpemUgbgogICAgaW50IGFycltuXTsKCiAgICAvLyBJbnB1dCB0aGUgZWxlbWVudHMgb2YgdGhlIGFycmF5CiAgICBjb3V0IDw8ICJFbnRlciB0aGUgZWxlbWVudHM6IiA8PCBlbmRsOwogICAgZm9yKGludCBpID0gMDsgaSA8IG47IGkrKykgewogICAgICAgIGNpbiA+PiBhcnJbaV07CiAgICB9CgogICAgLy8gQnViYmxlIFNvcnQgQWxnb3JpdGhtIHRvIHNvcnQgdGhlIGFycmF5IGluIGRlc2NlbmRpbmcgb3JkZXIKICAgIGZvcihpbnQgaSA9IDA7IGkgPCBuIC0gMTsgaSsrKSB7CiAgICAgICAgZm9yKGludCBqID0gMDsgaiA8IG4gLSAxIC0gaTsgaisrKSB7CiAgICAgICAgICAgIGlmKGFycltqXSA8IGFycltqICsgMV0pIHsKICAgICAgICAgICAgICAgIC8vIFN3YXAgdGhlIGVsZW1lbnRzIGlmIHRoZXkgYXJlIGluIHRoZSB3cm9uZyBvcmRlciAoZm9yIGRlc2NlbmRpbmcgb3JkZXIpCiAgICAgICAgICAgICAgICBpbnQgdGVtcCA9IGFycltqXTsKICAgICAgICAgICAgICAgIGFycltqXSA9IGFycltqICsgMV07CiAgICAgICAgICAgICAgICBhcnJbaiArIDFdID0gdGVtcDsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgIH0KCiAgICAvLyBEaXNwbGF5IHRoZSBzb3J0ZWQgYXJyYXkgaW4gZGVzY2VuZGluZyBvcmRlcgogICAgY291dCA8PCAiU29ydGVkIGVsZW1lbnRzIGluIGRlc2NlbmRpbmcgb3JkZXI6ICI7CiAgICBmb3IoaW50IGkgPSAwOyBpIDwgbjsgaSsrKSB7CiAgICAgICAgY291dCA8PCBhcnJbaV0gPDwgIiAiOwogICAgfQogICAgY291dCA8PCBlbmRsOwoKICAgIHJldHVybiAwOwp9Cg==