Program is :
#include<iostream.h
#include<conio.h>
void main()
{
clrscr();
int a[10],n,i,j,temp;
cout<<"Enter the number of elements";
cin>>n;
cout<<"Enter values";
a[0]=0;
for(i=1;i<=n;i++)
{
cin>>a[i];
}
for(i=2;i<=n;i++)
{
temp=a[i];
j=i-1;
while(temp<a[j])
{
a[j+1]=a[j];
j=j-1;
}
a[j+1]=temp;
}
cout<<"\n Sorted list is:";
for(i=1;i<=n;i++)
{
cout<<a[i]<<"\t";
}
getch();
}
Output is :
No comments:
Post a Comment