Program to sort an array of integers in ascending order using insertion sort.

#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
    int a[16], i, j, k, temp;
    cout<<"Keep Entering the elements\n";
   for (i = 0; i < 16; i++)
   {
       cin>>a[i];
   }
   for (i = 1; i < 16; i++)
   {
       for (j = i; j >= 1; j--)
       {
           if (a[j] < a[j-1])
           {
               temp = a[j];
               a[j] = a[j-1];
               a[j-1] = temp;
           }
           else
               break;
       }
}
    cout<<"sorted array\n"<<endl;
   for (k = 0; k < 16; k++)
   {
cout<<a[k]<<endl;
   }
cout<<"\n/*\nName-Sanjampreet Singh\nRoll Number-1507967\n*/";  
    getch();
}

Output:



-Thanks Sachin Bagga Sir

Comments

Popular posts from this blog

Program to illustrate the concept of templates.

Example of Synopsis in LaTeX

To create an html file to implement the concept of margin, padding using cascading style sheets.