Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main() {
- int n;
- cout << "Number of Elements: ";
- cin >> n;
- int arr[n];
- cout << "Enter " << n << " Elements: ";
- for(int i = 0; i < n; i++)
- cin >> arr[i];
- bool swapped = true;
- for(int j = 1; swapped; j++) {
- swapped = false;
- for (int i = 0; i < n - j; i++)
- if (arr[i] > arr[i + 1]) {
- swap(arr[i], arr[i + 1]);
- swapped = true;
- }
- }
- cout << "Sorted Array: ";
- for(int i = 0; i < n; i++)
- cout << arr[i] << " ";
- cout << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement