Program for Insertion sort


#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
 int i,j,k,n,m;
 cout<<"\nenter the no of integers : ";
 cin>>n;
 double a[n],temp;    // for any real numbers
 cout<<"\nenter the integers : ";
 for(i=0;i<n;i++)
 {
  cin>>a[i];
 }
 cout<<"\n\narray before sorting : ";
 for(i=0;i<n;i++)
 {
  cout<<a[i]<<" ";
 }
 cout<<"\n";
 for(i=1;i<n;i++)
 {
  for(j=0;j<i;j++)
  {
   if(a[j]>a[i])
   {
    temp=a[j];
    a[j]=a[i];
    for(k=i;k>j;k--)     // shifting of elements
    {
     a[k]=a[k-1];    
    }
    
    a[k+1]=temp;
   }

  }
 }
 cout<<"\n\nafter sorting the array : ";
 for(i=0;i<n;i++)
 {
  cout<<a[i]<<" ";
 }
 cout<<"\n";
return 0;
}