fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. int n, i, arr[50], j, temp;
  6. cout<<"Enter total number of elements :";
  7. cin>>n;
  8. cout<<"Enter "<<n<<" numbers :";
  9. for(i=0; i<n; i++)
  10. {
  11. cin>>arr[i];
  12. }
  13. cout<<"Sorting array using bubble sort technique...\n";
  14. for(i=0; i<(n-1); i++)
  15. {
  16. for(j=0; j<(n-i-1); j++)
  17. {
  18. if(arr[j]>arr[j+1])
  19. {
  20. temp=arr[j];
  21. arr[j]=arr[j+1];
  22. arr[j+1]=temp;
  23. }
  24. }
  25. }
  26. cout<<"Elements sorted successfully..!!\n";
  27. cout<<"Sorted list in ascending order :\n";
  28. for(i=0; i<n; i++)
  29. {
  30. cout<<arr[i]<<" ";
  31. }
  32.  
  33. return 0;
  34. }
Success #stdin #stdout 0s 15240KB
stdin
3
438
stdout
Enter total number of elements :Enter 3 numbers :Sorting array using bubble sort technique...
Elements sorted successfully..!!
Sorted list in ascending order :
0 0 438