fork download
  1. #include<iostream>
  2. using namespace std;
  3. int main(){
  4. int a[]={112,23,4,5,56,7};
  5. int n = sizeof (a)/sizeof (a[0]);
  6. cout<<"The array before sorting is"<<endl;
  7. for(int i=0;i<n;i++){
  8. cout<<a[i]<<" ";
  9. }
  10. cout<<endl;
  11. for (int i=1;i<n;i++){
  12. int key=a[i];
  13. int j;
  14. for(j=i-1;j>=0&&a[j]>key;j--){
  15. a[j+1]=a[j];
  16. }
  17. a[j+1]=key;
  18. }
  19. cout<<"The sorted array is"<<endl;
  20. for(int i=0;i<n;i++){
  21. cout<<a[i]<<" ";
  22. }
  23. ]
Success #stdin #stdout 0.03s 25852KB
stdin
Standard input is empty
stdout
#include<iostream>
using namespace std;
int main(){
    int a[]={112,23,4,5,56,7};
    int n = sizeof (a)/sizeof (a[0]);
    cout<<"The  array before sorting is"<<endl;
    for(int i=0;i<n;i++){
        cout<<a[i]<<" ";
    }
    cout<<endl;
    for (int i=1;i<n;i++){
        int key=a[i];
        int j;
        for(j=i-1;j>=0&&a[j]>key;j--){
            a[j+1]=a[j];
        }
        a[j+1]=key;
    }
    cout<<"The sorted array is"<<endl;
    for(int i=0;i<n;i++){
        cout<<a[i]<<" ";
    }
    ]