#include <iostream>
using namespace std;
void bubbleSort(int arr[], int n) {
// Outer loop to traverse the entire array
for (int i = 0; i < n - 1; i++) {
// Inner loop to perform comparison and swapping
for (int j = 0; j < n - i - 1; j++) {
// If the element is greater than the next, swap them
if (arr[j] > arr[j + 1]) {
// Swap the elements
int temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
void printArray(int arr[], int size) {
for (int i = 0; i < size; i++) {
cout << arr[i] << " ";
cout << endl;
int main() {
int arr[] = {64, 34, 25, 12, 22, 11, 90};
int n = sizeof(arr) / sizeof(arr[0]);
cout << "Original Array: ";
printArray(arr, n);
bubbleSort(arr, n);
cout << "Sorted Array: ";
printArray(arr, n);
return 0;