#include<stdio.h>
main()
{
int a[10],x,i,n,j;
printf("\n Enter the number of elements=");
scanf("%d",&n);
printf("\n Enter the elements=");
scanf("%d",&x);
i=0;
while(i<n)
{
j=i-1;
while(x<a[j] && j>=0)
{
a[j+1]=a[j];
--j;
}
a[j+1]=x;
if(i!=n-1)
{
printf("\n Enter value=");
scanf("%d",&x);
}
i++;
}
printf("\n Elements of array=");
for(i=0;i<n;i++)
printf("\t%d",a[i]);
}
main()
{
int a[10],x,i,n,j;
printf("\n Enter the number of elements=");
scanf("%d",&n);
printf("\n Enter the elements=");
scanf("%d",&x);
i=0;
while(i<n)
{
j=i-1;
while(x<a[j] && j>=0)
{
a[j+1]=a[j];
--j;
}
a[j+1]=x;
if(i!=n-1)
{
printf("\n Enter value=");
scanf("%d",&x);
}
i++;
}
printf("\n Elements of array=");
for(i=0;i<n;i++)
printf("\t%d",a[i]);
}
No comments:
Post a Comment