fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. // your code goes here
  6. int n;
  7. // cout<<"Enter number of numbers to be sorted: ";
  8. // cin>>n;
  9. // cout<<"Enter "<<n<<" numbers: ";
  10. n = 10;
  11. int arr[] = {4,8,1,3,6,2,10,7,5,9};
  12. // for(int i = 0;i<n;i++)
  13. // cin>>arr[i];
  14.  
  15.  
  16.  
  17. cout<<"Array before sorting: "<<endl;
  18. for(int i = 0;i<n;i++)
  19. cout<<arr[i]<<" ";
  20. cout<<endl;
  21.  
  22. for(int i = 0;i<n-i;i++){
  23. for(int j = 0;j<n-i-1;j++){
  24. if(arr[j]>arr[j+1])
  25. swap(arr[j],arr[j+1]);
  26. }
  27. }
  28.  
  29. cout<<"Array after sorting: "<<endl;
  30. for(int i = 0;i<n;i++)
  31. cout<<arr[i]<<" ";
  32. cout<<endl;
  33.  
  34. return 0;
  35. }
Success #stdin #stdout 0.01s 5284KB
stdin
Standard input is empty
stdout
Array before sorting: 
4 8 1 3 6 2 10 7 5 9 
Array after sorting: 
1 2 3 4 5 6 7 8 9 10