fork download
  1. // Online C++ compiler to run C++ program online
  2. #include <iostream>
  3. using namespace std;
  4. void bubble_sort(int a[]){
  5. // int ar[7]=a[7];
  6. for(int i=0;i<7;i++){
  7. for(int j=0;j<7-i-1;j++){
  8. if(a[j]>a[j+1]){
  9. int temp=a[j];
  10. a[j]=a[j+1];
  11. a[j+1]=temp;
  12. }
  13. }
  14. for(int k=0;k<7;k++){
  15. cout << a[k] << " "; }
  16. cout << endl;
  17. }
  18.  
  19. // printing sorted array
  20. cout << "Array after implementing bubble sort to it : ";
  21. for(int i=0;i<7;i++){
  22. cout << a[i] << " ";
  23. }
  24. }
  25. int main() {
  26. int arr[7];
  27. cout << "Enter elements of array : ";
  28. for(int i=0;i<7;i++){
  29. cin>> arr[i];
  30. }
  31. bubble_sort(arr);
  32. return 0;
  33.  
  34. }
  35.  
Success #stdin #stdout 0.01s 5268KB
stdin
Standard input is empty
stdout
Enter elements of array : 0 1 0 2 32767 -56273803 1349335032 
0 0 1 2 -56273803 32767 1349335032 
0 0 1 -56273803 2 32767 1349335032 
0 0 -56273803 1 2 32767 1349335032 
0 -56273803 0 1 2 32767 1349335032 
-56273803 0 0 1 2 32767 1349335032 
-56273803 0 0 1 2 32767 1349335032 
Array after implementing bubble sort to it : -56273803 0 0 1 2 32767 1349335032