Nafiz_Ahmed

Untitled

Jun 16th, 2020
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6. int arr[100],s,t,i,j;
  7. cout<<"Enter the size of the array: ";
  8. cin>>s;
  9.  
  10. cout<<"\n\nEnter elements of the array: ";
  11. for(i=0; i<s; i++)
  12. {
  13. cin>>arr[i];
  14. }
  15.  
  16. cout<<"\n\nElements of the array before sorting: ";
  17. for(i=0; i<s; i++)
  18. {
  19. cout<<arr[i]<<" ";
  20. }
  21. for(i=0; i<s-1; i++)
  22. {
  23. for(j=i+1; j<s; j++)
  24. {
  25. if(arr[i]>arr[j])
  26. {
  27. swap(arr[i],arr[j]);
  28. }
  29. }
  30. }
  31. cout<<"\n\nElements of the array after insertion sort: ";
  32. for(i=0; i<s; i++)
  33. {
  34. cout<<arr[i]<<" ";
  35. }
  36. cout<<"\n\n";
  37.  
  38. }
Advertisement
Add Comment
Please, Sign In to add comment